suzzane2020 Posted March 21, 2007 Share Posted March 21, 2007 HI, Iam stuck on a problem here and hope someone wud help I have a table with each row having 3 columns . And these rows are populated from a database. how do i get the values of each row using javascript? this is the javascript i have been using: function get_order() { var x = document.getElementById("rowid"); var items = x.getElementsByTagName("td"); var itemsString = ""; for (var i = 0; i < items.length; i++) { if (itemsString.length > 0) itemsString += ":"; itemsString += items[i].innerHTML; } } The prob here is that i only get the first row from the database . Plz help Thnk You Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted March 21, 2007 Author Share Posted March 21, 2007 ??? Quote Link to comment Share on other sites More sharing options...
paul2463 Posted March 21, 2007 Share Posted March 21, 2007 dont know if this will make much difference but I have put curly braces around you if statement function get_order() { var x = document.getElementById("rowid"); var items = x.getElementsByTagName("td"); var itemsString = ""; for (var i = 0; i < items.length; i++) { if (itemsString.length > 0) { itemsString += ":"; itemsString += items[i].innerHTML; } } } Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted March 21, 2007 Author Share Posted March 21, 2007 I tried that but it gives no rows this time Quote Link to comment Share on other sites More sharing options...
paul2463 Posted March 21, 2007 Share Posted March 21, 2007 because itemString.length is an emtpy string at that point, so you will probably have to take that bit out or figure another way to do the if statement based on what you actually want it to do Quote Link to comment Share on other sites More sharing options...
fenway Posted March 22, 2007 Share Posted March 22, 2007 Why not just write out the values into JS from PHP? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted March 23, 2007 Share Posted March 23, 2007 i would personally give each tr an id and then each td an id <tr id="row_1"><td id="cell:1:1"></td><td id="cell:1:2">.... function getRow(rowNum){ var string = ''; for(i = 1; i < 4; i++){ string += (i != 1 && i != 4) ? ':' : ''; string += document.getElementById('cell:'+ rowNum +':'+ i).innerHtml; } return string; } Quote Link to comment Share on other sites More sharing options...
fenway Posted March 23, 2007 Share Posted March 23, 2007 Yeah, sure, but if the values can't change, why bother having look them up in the DOM? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.