473,659 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting td value

Given the id of a tr, does anyone know how to get a value of a td of
that tr?
Jun 6 '06 #1
9 27231
turnitup wrote on 06 jun 2006 in comp.lang.javas cript:
Given the id of a tr, does anyone know how to get a value of a td of
that tr?


<TD>s do not have a value.

=============== =============== ==========

<table><tr id=myTr><td>bla h</td></tr></table>
<script type='text/javascript'>
var r = document.getEle mentById('myTr' ).firstChild.in nerHTML
alert(r)
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 6 '06 #2
Evertjan. wrote:
turnitup wrote on 06 jun 2006 in comp.lang.javas cript:
Given the id of a tr, does anyone know how to get a value of a td of
that tr?


<TD>s do not have a value.

=============== =============== ==========

<table><tr id=myTr><td>bla h</td></tr></table>
<script type='text/javascript'>
var r = document.getEle mentById('myTr' ).firstChild.in nerHTML
alert(r)
</script>


Thank you, of course I meant innerHTML!!
Jun 6 '06 #3
turnitup wrote:
Evertjan. wrote:
turnitup wrote on 06 jun 2006 in comp.lang.javas cript:
Given the id of a tr, does anyone know how to get a value of a td of
that tr?


<TD>s do not have a value.

=============== =============== ==========

<table><tr id=myTr><td>bla h</td></tr></table>
<script type='text/javascript'>
var r = document.getEle mentById('myTr' ).firstChild.in nerHTML
alert(r)
</script>


Thank you, of course I meant innerHTML!!


Here's a longer version which just uses the DOM:

var r = document.getEle mentById('myTr' ).firstChild.fi rstChild.data

The second "firstChild " is the text node within the tr element that
contains "blah".

--
Kam-Hung Soh
http://kamhungsoh.blogspot.com - It Mostly Works
http://members.optusnet.com.au/khsoh - Software That Mostly Works

Jun 7 '06 #4
Kam-Hung Soh wrote:
turnitup wrote:
Evertjan. wrote:
turnitup wrote on 06 jun 2006 in comp.lang.javas cript:

Given the id of a tr, does anyone know how to get a value of a td of
that tr?
<TD>s do not have a value.

=============== =============== ==========

<table><tr id=myTr><td>bla h</td></tr></table>
<script type='text/javascript'>
var r = document.getEle mentById('myTr' ).firstChild.in nerHTML


That method is dependent on the markup in some browsers. If whitespace
is introduced between the TR and TD tags (e.g. <tr ...> <td>...), then
the TR's first child will be a #text node, not the TD in Firefox and I
think other Gecko browsers too.

A better idea is to use the cells collection:

var tr = document.getEle mentById('myTr' );
var td = tr.cells[0];

From memory, Safari 1.0.3 (Mac OS X 10.2) does not properly implement
the table row's cells collection - if that's an issue, you can use
getElementsByTa gName:

var td = tr.getElementsB yTagName('td')[0];

A final method is to walk down the child nodes until a TD is encountered:

var td = tr.firstChild;
while (td && 'td' != td.tagName.toLo werCase() ){
td = td.nextSibling;
}

If there are no TDs in the row, td will be undefined but then the HTML
would be invalid in the first place.

I think that about covers the reasonable methods, take your pick.
[...]

--
Rob
Jun 7 '06 #5
RobG wrote on 07 jun 2006 in comp.lang.javas cript:
Kam-Hung Soh wrote:
No, you left Kam-Hung's relay out of your quote!
turnitup wrote:
Evertjan. wrote:
turnitup wrote on 06 jun 2006 in comp.lang.javas cript:

> Given the id of a tr, does anyone know how to get a value of a td
> of that tr?
<TD>s do not have a value.

=============== =============== ==========

<table><tr id=myTr><td>bla h</td></tr></table>
<script type='text/javascript'>
var r = document.getEle mentById('myTr' ).firstChild.in nerHTML


That method is dependent on the markup in some browsers. If
whitespace is introduced between the TR and TD tags (e.g. <tr ...>
<td>...), then the TR's first child will be a #text node, not the TD
in Firefox and I think other Gecko browsers too.


Your below ideas are better indeed.
A better idea is to use the cells collection:

var tr = document.getEle mentById('myTr' );
var td = tr.cells[0];

From memory, Safari 1.0.3 (Mac OS X 10.2) does not properly implement
the table row's cells collection - if that's an issue, you can use
getElementsByTa gName:

var td = tr.getElementsB yTagName('td')[0];

A final method is to walk down the child nodes until a TD is
encountered:

var td = tr.firstChild;
while (td && 'td' != td.tagName.toLo werCase() ){
td = td.nextSibling;
}

If there are no TDs in the row, td will be undefined but then the HTML
would be invalid in the first place.

I think that about covers the reasonable methods, take your pick.


Since the page's HTML is your own,
why not simply ensure there is no white space?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 7 '06 #6
Evertjan. wrote:

Since the page's HTML is your own,
why not simply ensure there is no white space?


The OP can do that, but I think it creates a maintenance issue - if at
any time in the future the HTML is modified, it is quite possible that
whitespace will be introduced.

Thinking on it a little more, I think a span with an ID should be used
and the date string written to that using getElementById. It means the
span can be put anywhere in the document and removes issues related to
wandering down the DOM tree, such as the different treatment of
whitespace by various browsers and extra elements being introduced (say
the date gets moved to the second cell, or a table-less layout is
adopted). :-)
--
Rob
Jun 7 '06 #7
RobG wrote:
The OP can do that, but I think it creates a maintenance issue - if at
any time in the future the HTML is modified, it is quite possible that
whitespace will be introduced.

Thinking on it a little more, I think a span with an ID should be used
and the date string written to that using getElementById. It means the
span can be put anywhere in the document and removes issues related to
wandering down the DOM tree, such as the different treatment of
whitespace by various browsers and extra elements being introduced (say
the date gets moved to the second cell, or a table-less layout is
adopted). :-)


I think it's a neat idea! It separates the content (so to speak) from
the markup.

I can feel a design pattern coming on ....

--
Kam-Hung Soh
http://kamhungsoh.blogspot.com - It Mostly Works
http://members.optusnet.com.au/khsoh - Software That Mostly Works

Jun 8 '06 #8
Kam-Hung Soh wrote on 08 jun 2006 in comp.lang.javas cript:
RobG wrote:

[..]

Thinking on it a little more, I think a span with an ID should be
used and the date string written to that using getElementById. It
means the span can be put anywhere in the document and removes issues
related to wandering down the DOM tree, such as the different
treatment of whitespace by various browsers and extra elements being
introduced (say the date gets moved to the second cell, or a
table-less layout is adopted). :-)


I think it's a neat idea! It separates the content (so to speak) from
the markup.

I can feel a design pattern coming on ....


In practice, you build all large tables needing the wanted features by
serverside code, so that having each element id-ed and css-classed is
defaultly incorporated. Most features can then be css and javascript
driven.

Would you call that a design pattern?

ASP-VBS example:

<% newTable "myTable" %>
<% newHeadRow %>
<% newCell "cell content 7" %>
<% newCell defaultCellCont ent %>
<% newBodyRow %>
<% newCell defaultCellCont ent %>
<% newCell "cell content 777" %>
<% endTable %>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 8 '06 #9
Evertjan. wrote:
In practice, you build all large tables needing the wanted features by
serverside code, so that having each element id-ed and css-classed is
defaultly incorporated. Most features can then be css and javascript
driven.

Would you call that a design pattern?

ASP-VBS example:

<% newTable "myTable" %>
<% newHeadRow %>
<% newCell "cell content 7" %>
<% newCell defaultCellCont ent %>
<% newBodyRow %>
<% newCell defaultCellCont ent %>
<% newCell "cell content 777" %>
<% endTable %>


Yes, I agree.

I was thinking of AJAX or Javascript-driven pages in my previous post.
Sorry for not stating the context.

--
Kam-Hung Soh
http://kamhungsoh.blogspot.com - It Mostly Works
http://members.optusnet.com.au/khsoh - Software That Mostly Works

Jun 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6907
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
6
2244
by: melanieab | last post by:
Hi, Easy question. It seems to me that I'm following the examples correctly, but apparently I'm not. I'm trying to retrieve the data from a row called "row" and a column called "File". This is what I have: (xFile is the int value in column File and tCat is the table) First I try: xFile = int.Parse((tCat.Rows).ToString()); Another example I found:
5
1724
by: Manjiri | last post by:
Hello Everybody... Here i have the program which prints how many number of times the element appears in the array.... The code is as follows... #include<iostream.h> class Count
4
4571
by: bushi | last post by:
hi ! i have following code to display some text on a web form,after getting it from database. <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <asp:LinkButton ID="links" runat="server" Text='<%# Eval("links") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />
1
3187
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as follows: The code below is for the first page:session_start is in line 3 <link href="css/jobSheet.css" rel="stylesheet" type="text/css" /> session_start();
33
11841
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon (NT_AUTHORITY\SYSTEM). I understand that when the service starts, no user may be logged in, but that's ok, as the app I am monitoring can only be run by a logged in user. Do I need to use WMI to get the user context of Explorer.exe or is there a...
10
1684
by: Mike | last post by:
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an 'input string was not in a correct format.' Code: foreach (GridViewRow row in grid.Rows) { CheckBox chk = (CheckBox)gr.FindControl("checkbox"); if (chk.Checked) {
0
2909
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form action="/login"> <html:text property="userName" value="Bunty"/> <html:submit/>
13
2073
by: jcato77 | last post by:
I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the entire inventory. I have what I think is the correct code but it's not working. Help is greatly appreciated class Inventory3 { public static final int MAXIMUM_ITEMS = 4; private static Product product = new Product; public static void...
9
3534
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why this happens. This is my part of code given below. <%@ Language=VBScript%> <%Option Explicit%> <html> <head> <title>SABF</title> <!--#include file="font.css"-->
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.