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

 

 

Link to comment
Share on other sites

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;

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.