File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes HOW TO PICK UP DATA FROM AN HTML TABLE CELL/COLUMN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "HOW TO PICK UP DATA FROM AN HTML TABLE CELL/COLUMN" Watch "HOW TO PICK UP DATA FROM AN HTML TABLE CELL/COLUMN" New topic
Author

HOW TO PICK UP DATA FROM AN HTML TABLE CELL/COLUMN

Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57
In my Javascript program, I want to pick up the data/value FROM the cell/column of an HTML table and assign it to a variable. Can you please tell how to refer to the data/value of a cell/column of an HTML table? For example in an HTML form, the value of a field can be picked up by specifying:
document.forms[0].firstName.value, how can I pick up the value of a cell in an HTML table?

Thank you.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You will need to use innerHTML is what you can use to grab the text.

If the cell you want is named it is rather easy all you need to do is reference the id


But if you do not have an id to go by, it takes a couple more steps, but it is not that hard as long as you know the number of the row it is in and the number of the cell it is in:


If you have the row named, or you have the row object, you can just do:


Hope that helps you out.

Eric
[edit - fixed a simple typo]
[ January 13, 2005: Message edited by: Eric Pascarello ]
Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57
Super!

Your answer is quite exaustive. In a ddition, it is exactly what I asked for.

Thank you very much indeed.

Dele.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Glad I could help
kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
HI ERic
cant we use innerText instead of innerHTML. like document.getElementById("cellid").innerText;
THanks
kundan


SCJP1.4,SCBCD,SCEA,CNA
Failures are practice shoots for success.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can feel free to us innerText, but you need to realize that innerText is IE only. Mozilla based browsers will get undefined.

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I blogged today about how to make innerHTML act like innerText

http://radio.javaranch.com/channel/pascarello/2005/01/14/1105721395000.html

Eric
kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
THanks Eric
Your blog really helped?? Actually i just forgot the issue of compatibility since my project is IE based.
Thanks again
kundan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HOW TO PICK UP DATA FROM AN HTML TABLE CELL/COLUMN
 
Similar Threads
JTable... Urgent!
JTable problem
To add focusLost event to individual cell of JTable
query
Cell renderer for different JComboBox's in same column?