• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem in getting table cell value in HTML using java script

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic