chris
chris

Reputation: 65

Get data out of html table cells

I have a huge html table that I am building dynamically, and I want to be able to get cell data out of it easily.
Here is how my table is set up.

   <tr><td  id="presCode0">V</td></tr>
    <tr><td  id="presCode1">F</td></tr>

Each row element is numbered when I build my table. Each row has 5 cells and there are hundreds of rows in the table. Each row when clicked calls a function like this:

onclick="switchToRequest(rownumber)"    

I have tried using:

function switchToRequest(i)
{
var presCode=''+'presCode' + i + '';
attend.elements["codePick"].value=presCode.innerHTML;
attend.elements["codePick"].value=$("#"+"presCode"+i);
}

is there any way that I can get table cell values out of a complex table using Javascript?

Upvotes: 0

Views: 3312

Answers (3)

yoozer8
yoozer8

Reputation: 7489

Replace

presCode.innerHTML;

with

$("#"+presCode).innerHTML;

and remove the second attend.elements line

Upvotes: 0

Samir Adel
Samir Adel

Reputation: 2499

function switchToRequest(i)
{
var presCode=''+'presCode' + i + '';
attend.elements["codePick"].value=document.getElementById(presCode).innerHTML;
attend.elements["codePick"].value=$("#"+"presCode"+i);
}

Upvotes: 0

Mrchief
Mrchief

Reputation: 76258

Try this:

attend.elements["codePick"].value = $("#"+"presCode"+i).html();

or

attend.elements["codePick"].value = $("#"+"presCode"+i).text(); // to get text minus html tags

Upvotes: 1

Related Questions