Jump to content

Document.getelementbyid Is Not Working For Me...


confused and dazed

Recommended Posts

Here is a little more code... I am using JSON to send values to the browser $result = mysql_query("SELECT r1, r2, r3 FROM database1 WHERE grp='a'", $con);$rows = array();while ($row = mysql_fetch_assoc($result)) { $rows[] = array( 'id' => 'b1', 'value' => $row['r1'] ); $rows[] = array( 'id' => 'b2', 'value' => $row['r2'] ); $rows[] = array( 'id' => 'b3', 'value' => $row['r3'] ); }$json = json_encode($rows);echo '<script type="text/javascript">var Tload = '.$json.';</script>';?><script type="text/javascript">alert(typeof Tload); // check if Tload var existsalert(Tload.length); // check length of arraywindow.onload = function() {for (var i = 0; i < Tload.length; i++) { document.getElementById(Tload.id).value = Tload.value; }}; The alerts say that it is an object with 3 for length... What am I doing wrong? It will not load the town names...

Link to comment
Share on other sites

Then it should work, arrays values items are listed, input form elements have unique id ref of id="b1", id="b2 and" id="b3", so theres not much else we can suggest unless! we see the whole code and not bits, and pieces (I think i've mentioned this before) so we can identify maybe a conflict that is preventing this code from working correctly.

Link to comment
Share on other sites

I have absolutely created those ids in the form... this is so frustrating...
show us that part of the code too, then.
Link to comment
Share on other sites

right, but when you post javascript that is reliant on the markup (i.e. using ID's and DOM manipulation) it's pretty much in good form to post the markup too, because they are coupled at that point and thus would be helpful for seeing the bigger picture for us when debugging; as this case plainly showed. If you were just writing a JS function to compute some sort of algorithm, or confirming some sort of advanced coding technique, then yeah, only the JS would really be required.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...