*
The moose likes HTML, CSS and JavaScript and the fly likes Problem in getting table cell value in HTML using java script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem in getting table cell value in HTML using java script" Watch "Problem in getting table cell value in HTML using java script" New topic
Author

Problem in getting table cell value in HTML using java script

Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Hi all,

I am new in javascript.

I am trying to get cell (td) value but unable to get.
I am using Safari/Firefox in MAC OS X.
please help me..
following is my code..






regards
Ranveer k Kumar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
Are you certain that the "tdId" element is the first child of the "trId" element? Examine the type of the first child node to find out for sure.

Also, if you really want "tdId", why start with "trId"?


Ping & DNS - my free Android networking tools app
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Ulf Dittmer wrote:Are you certain that the "tdId" element is the first child of the "trId" element? Examine the type of the first child node to find out for sure.

Also, if you really want "tdId", why start with "trId"?


Hi Ulf Dittmer,
thanks for reply...

yes, this is static page for demo only.. so only one child of trId.

Actually I am trying to get value from td cell so I tried but still not getting value..

still alert is giving "undefined" message.
...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
yes, this is static page for demo only.. so only one child of trId.

What I was getting at was that it may *not* be the first element, despite how things may look to you. That's why I advised to check what the first element actually is.

Actually I am trying to get value from td cell so I tried but still not getting value.

What code did you use for that?
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Ulf Dittmer wrote:
What code did you use for that?


same code I am using except I removed the id ="tdId" from td tag.

rest of things are same..

please advice me I am very new to java script.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
same code I am using except I removed the id ="tdId" from td tag.

How can you select the cell directly if you remove the ID tag?

If you select the TD element, then you'd use innerHTML directly; leave out the ".firstChild".

And again, since you're new to this, you may want to iterate through the DOM hierarchy to get a feeling for how it may be structured, and how to access child and sibling elements.
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Ulf Dittmer wrote:
same code I am using except I removed the id ="tdId" from td tag.

How can you select the cell directly if you remove the ID tag?

If you select the TD element, then you'd use innerHTML directly; leave out the ".firstChild".


thanks for suggestion...

my table is



Now I am getting value by

working..


but still unable to get value by the

not working..


I must missing some thing..
please help.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
document.getElementById("trId1").firstChild is probably not what you think it is.

http://www.javascriptkit.com/domref/nodetype.shtml

Eric
Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
You can get cell value with JS even when click on the cell:



I wrote the HTML table in JSP.
**Course** is is a type. For example Course cs, cs= object of type Course which had 2 attributes: id, title.
**courses** is an ArrayList of Course objects.

The HTML table displays all the courses titles in each cell. So the table has 1 column only:
Course1
Course2
Course3
......
Taking aside:



This means that after user selects a table cell, for example "Course2", the title of the course- "Course2" will travel to the page where the URL is directing the user: . "Course2" will arrive in FoundS.jsp page. The identifier of "Course2" is courseId. To declare the variable courseId, in which CourseX will be kept, you put a "?" after the URL and next to it the identifier.
It works.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60789
    
  65

Please do not post JSP markup in the HTML forum. Also your example is way too broad and doesn't focus on the original question. Please limit solutions to those that target the question rather than embedding it into a larger, more complicated, example.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in getting table cell value in HTML using java script
 
Similar Threads
unable to do validation for select in struts2
Get Rows from a Table
struts-2 (set values to action class)
non english characters in login-form
spaces while populating using s:iterator