Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in getting table cell value in HTML using java script

 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"?
 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.getElementById("trId1").firstChild is probably not what you think it is.

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

Eric
 
Kyupa Supa
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic