Connecting Tech Pros Worldwide Help | Site Map

get data from html table

  #1  
Old August 26th, 2008, 01:22 PM
Newbie
 
Join Date: Aug 2008
Posts: 6
Hi,
I have a html table with data.
Now when I select a particular row, I need the data of all the cells of that row
how would I do

Kindly help
Thanx in advance
  #2  
Old August 26th, 2008, 02:16 PM
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 344

re: get data from html table


Hi Ashish, hope this would help u out

[HTML]<html>
<head>
<script type="text/javascript">
function doThis(ths)
{
var x=(ths.id).toString();
var i=x.indexOf('r');
var num = parseInt(x.substring((i+1),x.length));
var table = document.getElementById("myTable");
var row = table.rows[num-1];
var first=row.cells[0].innerHTML;
var second = row.cells[1].innerHTML;
document.getElementById('myText1').value=first;
document.getElementById('myText2').value=second;
}
</script>
</head>
<body>
<p>Click on any Element in the Table</p>
<br/>
<table id="myTable" border="1" cellpadding="5" cellspacing="5">
<tr id="tr1" onclick="doThis(this)">
<td>Hai1</td><td>Hello1</td>
</tr>
<tr id="tr2" onclick="doThis(this)">
<td>Hai2</td><td>Hello2</td>
</tr>
<tr id="tr3" onclick="doThis(this)">
<td>Hai3</td><td>Hello3</td>
</tr>
<tr id="tr4" onclick="doThis(this)">
<td>Hai4</td><td>Hello4</td>
</tr>
<tr id="tr5" onclick="doThis(this)">
<td>Hai5</td><td>Hello5</td>
</tr>
</table> <br/>
<input type="text" id="myText1">&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="myText2">
</body>
</html>[/HTML]

Any doubts or any probs post back it. I will try to help u out


Regards
Ramanan Kalirajan
  #3  
Old August 26th, 2008, 03:33 PM
Newbie
 
Join Date: Aug 2008
Posts: 6

re: get data from html table


Hi Ramanan ,

Thanx buddy,it really works
thanx a lot , u have solved a big issue
I am heartly thankful to u

God Blees u my dear frend

Regards
Ashish

Last edited by gits; August 27th, 2008 at 11:05 AM. Reason: drop quote
  #4  
Old August 27th, 2008, 04:55 AM
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 344

re: get data from html table


Quote:
Originally Posted by Ashish101
Hi Ramanan ,

Thanx buddy,it really works
thanx a lot , u have solved a big issue
I am heartly thankful to u

God Blees u my dear frend

Regards
Ashish
Hello Ashish be thankful to this forum. And try to help lot of guys like you. All the best. if any doubts or problem post it in the forum. I will try to help u out.

Regards
Ramanan Kalirajan
  #5  
Old August 27th, 2008, 11:25 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,525
Provided Answers: 12

re: get data from html table


The rowIndex property should be enough and can replace the first few lines of the doThis() function, i.e. ths.rowIndex can be used to index the table rows[] array.
  #6  
Old August 27th, 2008, 11:50 AM
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 344

re: get data from html table


Quote:
Originally Posted by acoder
The rowIndex property should be enough and can replace the first few lines of the doThis() function, i.e. ths.rowIndex can be used to index the table rows[] array.
Hi Acoder, I tried it for dynamic data retrieval from the table. (i.e tr created dynamically) i just posted him the static one. The code can be simplified. thanks for the suggestion

Regards
Ramanan Kalirajan
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regexp get data from html page Andelys answers 5 April 22nd, 2008 07:10 PM
Need to read data from HTML table into an array ducky801 answers 1 January 5th, 2007 11:05 PM
Extract Data from HTML source Leon answers 5 October 25th, 2006 04:35 PM
Dataset - How to get data from a child table? Kay answers 11 December 1st, 2005 02:55 AM