JavaScript - I'm A Bit Lost With Js : )
Hi all,
here are two pieces of javascript code, I'm trying to make them both do the same thing but I really need some help. The first code works and the second does not. Here I predefine the variable, then I give it a place to be displayed. ---- var x=(Math.floor(Math.random()*5)); document.getElementById("information").innerHTML=x; //works ---- The next code is the same thing but in reverse. Here I predefine where to displayed the variable, then I give it the variable. ---- var x=document.getElementById("information").innerHTML; x=(Math.floor(Math.random()*5)); //not working ---- Is there any way that I could get this second code to work? I realise that x is being fulled with the inner HTML of "information" and then begin replaced with the random number. I don't know how to store x with a command and not simply the result of a command. I have tryed... x="document.getElementById(\"information\").innerHTML"; ...but then it's just a string. The last line replaces what ever is being stored in x. I don't know how to tell java script that this variable is for showing where the information is going, not just another place to store that information. I was thinking it would look something like... (x)=(Math.floor(Math.random()*5)); ...because it's the contact of x that I'm interested in and not x itself. I'm a bit lost here, any help would be appreciated. Thanks for your time. Similar TutorialsWould someone look at the code in my program at http://www.ckdoublenecks.com/prorent.html . I need to make the "amt paid" column an input field and then make changes to other fields if the "amt paid" field is Not " " (?). Thanks in advance.
Hello there, I'm a 30yr old returning to school and I signed up for a CMIS102 class, thinking it be more explanatory as the syllabus let on. But I was wrong. While I do understand some of what the professor has been teaching us, like modular programming and IfElse statements, I can't wrap my head around things like While Loops. My professor has saddled us with a couple assignments, requiring us to write in pseudocode and I was wondering if anyone could explain what he wants from this assignment or even help me with it, that maybe I can finally have a grasp of it, and will know what I'm doing on the final. ~Tia P.S. I've posted the assignment question below: I need to write a pseudo-codepseudocode for the following question but don't know how: Write a program to read a list of exam scores (in the range 0 to 100) and to output the total number of grades and the number of grades in each letter=grade category. The end input is indicated by a negative score as a sentinel value. (The negative value is used only to end the loop, so do not use it in the calculations. Example: 88 93 55 77 100 -1 (The output would be) Total number of grades = 5 Number of A's =2 Number of B's = 1 Number of C's =1 Number of D's = 0 Number of F's =1 Must prompt user to run again I am new to JavaScript and looking for its specification so I can learn from the manual. I see its made by Netscape, which is now liquidated... and cannot find a consortium for it.. so, am I correct in guessing its now a lost tribe?
Hey, I have been using a tr onclick function in my tables to change the color of the most recently clicked row, it works fine. I have recently added sorttable http://www.kryogenix.org/code/browser/sorttable/ to my table with the simple <table class="sortable"> Making the table sortable has overwritten my tr onclick functions, which are now dead. Any ideas/thoughts? Heres a quick sample of what it looks like: Code: <table class="sortable"> <thead><th scope="col">Header 1</th> <th scope="col">Header 2</th></thead> <tr onclick="doSomething(this);"><td>Some data</td><td>Some more</td></tr> </table> Code: // Code for alternating row colors on data tables, but NOT every table.... just ones with classname="altRows" // Note: rowID comes from the JIT Variable: &&_sflalt // Note: This function is called in ovject group: *TR in the MLS Syntax File function stripeRows(rowVar) { // Need to create a var for uniquely identifying the highlighted rows var rowID = 0; // Begin the checking and writing of the HTML data if (rowVar == '') { var html = "<tr>"; document.writeln(html); } else if (rowVar == '0') { var html = "<tr class=\"rowEven\" id=\"evenRow"+rowID+"\" onmouseover=\"highlightRow('over', 'evenRow"+rowID+"');\" onmouseout=\"highlightRow('out', evenRow"+rowID+"');\">"; document.writeln(html); rowID++; } else if (rowVar == '1') { var html = "<tr class=\"rowOdd\" id=\"oddRow"+rowID+"\" onmouseover=\"highlightRow('over', 'oddRow"+rowID+"');\" onmouseout=\"highlightRow('out', oddRow"+rowID+"');\">"; document.writeln(html); rowID++; } else { var alertText = "Something went wrong with alternating row color in datasets - The function broke. Please jot down a note as to what you were doing when this dialogue box poped up, and let American Health Care Software know \n\n\n ATTN: Pat Litke"; parent.showDialog('Broken Function',alertText,'prompt'); } } // Function for modifying class attrbutes for row highlighting.. // This function will allows the currently moused-over row to highlight a different color based on its ID function highlightRow(option, theRowID) { var row = document.getElementById(theRowID); if(option == 'over') { row.className = 'rowOver'; } if(option == 'out') { row.className = 'rowEven'; } else if(option == 'in') { row.className = 'rowOdd'; } else { } } Can someone help? I can't figure out why this isn't working the way that I'm logically seeing it... The alternate rows highlight works fine, but the mouseover and mouseout events fail miserebly... When a page loads, regardless of where i mouse over, only the top two rows color in with the mouseOver color. They also don't revert to original coloring. Where am I going wrong? Note: I apologize if it's something little that I'm missing... I'm still new to js Hi, I have this ajax routine... Code: function xhr_get(target_str,async){ var sync=true; if(async){sync=false;} var xhr = new XMLHttpRequest(); xhr.open('GET', target_str, sync); if(sync==false){ xhr.onreadystatechange = function () { if (xhr.status === 200) { try{ var ii =JSON.parse(xhr.responseText);} catch (exception) { } if(ii){ return ii; }else{ alert(xhr.responseText); return false; } } else { alert(xhr.status+' '+target_str);return false; } }; xhr.send(null); }else{ xhr.send(null); try{ var ii =JSON.parse(xhr.responseText);} catch (exception) { } if(ii){ return ii; }else{ alert(xhr.responseText); return false; } } } now if I alert(ii) on success the data I am looking for (specifically ii.content) shows up in the alert as expected however when calling from another javascript function, ii is false ???? please explain, Code: function call_change_val(fld,vm_id){ var str='?_f=load_edit_fld&_ctl_fld='+fld+'&vm_id='+vm_id+'&fld='+fld+'&width=80'; i = xhr_get('ajax/val_main_loader.php'+str,true); ////////////////////// alert(i); or alert(i.content) here both give be a blank popup///////////////// showdiv('c_change_'+fld); setih('c_change_'+fld,i.content); } I expected alert(i) to say Object or similar, getting nothing |