473,412 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

How can I extract this table cell value?

Will Javascript allow me to extract the value 'NWEINETTE' (value from
first td) from the following HTML?

<tr id="lightrow" class="data">
<td class=data id='USER_NAME' nowrap><A class='data'
HREF="user_profile.jsp?LOGIN=NWEINETTE">NWEINETTE</A>&nbsp;&nbsp;&nbsp;</td>
<td class=data id='FIRST_NAME' nowrap>nancy&nbsp;&nbsp;&nbsp;</td>

<td class=data id='MIDDLE_NAME' nowrap>f&nbsp;&nbsp;&nbsp;</td>
<td class=data id='LAST_NAME' nowrap>weinette&nbsp;&nbsp;&nbsp;</td>
</tr>

Ideally, it would be great if I could find some cross-browser (IE 6+,
Netscape 7+) JS that could do the task.

Thanks, - Dave
Jul 23 '05 #1
2 2320
Hi Dave,

try this:

// get a ref to the row
var theRow = document.getElementById("lightrow");
// get the first link
var theLink = theRow.getElementsByTagName("A")[0];
// your value
alert(theLink.innerHTML);

this should work in any dom compliant browser..

regards
Jul 23 '05 #2
On 10 Oct 2004 06:11:32 -0700, asmo <Ja***********@gmx.de> wrote:

Please quote relevant text from the post you are responding to, including
who wrote that post.
// get a ref to the row
var theRow = document.getElementById("lightrow");
// get the first link
var theLink = theRow.getElementsByTagName("A")[0];
// your value
alert(theLink.innerHTML);

this should work in any dom compliant browser..
Why? The innerHTML property isn't defined as part of the DOM, though it is
supported by the "major" browsers.

A solution that is fully DOM-compliant is:

var user = document.getElementById('USER_NAME');
// value:
user.firstChild.firstChild.data

This makes a couple of assumptions:

1) The id, USER_NAME, is unique. Whilst this should be the case anyway as
id values must be unique, I don't get that impression from the HTML
provided by the OP.
2) There is no whitespace between the opening cell and link tags. If there
is whitespace, the code becomes a little more involved, but simple
nevertheless.
On 9 Oct 2004 21:47:16 -0700, D. Alvarado <la***********@zipmail.com>
wrote:
<tr id="lightrow" class="data">
<td class=data id='USER_NAME' nowrap><A class='data'
HREF="user_profile.jsp?LOGIN=NWEINETTE">NWEINETTE</A>&nbsp;&nbsp;&nbsp;</td>


If you need to pad an element, use the CSS padding property. With the
markup you presented, the rule

#lightrow td {
padding-right: 3ex;
}

would achieve what the non-breaking spaces do, but with the benefit of not
being a hack. A different selector might be more appropriate, depending
upon the rest of your page.

A small request when posting code: please don't use tabs. They can cause a
significant amount of wrapping. Instead, use spaces - two is probably be
the best, considering the limited width.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

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

Similar topics

9
by: Brian Hanson | last post by:
Hi, I have an unusual problem that just showed its ugly head at a pretty bad time. I have an asp.net (VB) app that takes data from an Excel sheet and puts it into SQL Server. I get the data...
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
2
by: dschectman | last post by:
This appears to be a feature of IE JavaScript. I am running IE 6.0 with the latest patches from Microsoft. Are there any workarounds other than re-coding the source HTML to place all the...
7
by: slitvinov | last post by:
I am learning Relax NG. The problem is that I cannot figure out how to make a schema for a table. In my case I would like to make a table with any name of child elements (columns) but columns...
6
by: anirban.anirbanju | last post by:
hi there, i've some serious problem to add rows dynamically in a table. my table contains 5 cell. | check | from_value | to_value | color_text | color_value |...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
2
by: newUser1234 | last post by:
I've been trying to extract time from excel sheet cell to a vb text box, instead of giving me the time it gives me a double type number like "0.4375", in the excel file that cell has the value 10:30...
4
by: frankentux | last post by:
Hi there, I'm losing hair trying to figure out how I can actually get the text out of an existing .ods file. Currently I have: #!/usr/bin/python from odf.opendocument import Spreadsheet from...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.