Jump to content

getting row values by javascript


suzzane2020

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/43722-getting-row-values-by-javascript/
Share on other sites

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;
    }
  }   
}

 

 

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;

}

 

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.