473,406 Members | 2,549 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,406 software developers and data experts.

Counting links in table rows

Hi

I need to write a script that will allow me to check the value of any link in a table cell. The desired result would be something like this:
Expand|Select|Wrap|Line Numbers
  1. row[0].cell[2].innerHTML
, allowing me to call the contents of the fourth cell in the first row.

The following script may be of use as a starting point:

Expand|Select|Wrap|Line Numbers
  1. <table id="table">
  2. <tr>
  3. <td><a href="#">hello1</a></td>
  4. <td><a href="#">hello2</a></td>
  5. </tr>
  6. <tr>
  7. <td><a href="#">hello3</a></td>
  8. <td><a href="#">hello4</a></td>
  9. </tr>
  10. </table>
  11.  
  12. <script type="text/javascript">
  13. window.onload = function() {
  14.     var table = document.getElementById('table');
  15.     var rows = table.getElementsByTagName('tr');
  16.     for (i=0; i < rows.length; i++) {
  17.         var cells = rows[0].getElementsByTagName('td');
  18.         for (j=0; j < cells.length; j++) {
  19.             alert(cells[1].getElementsByTagName('a').innerHTML); // Desired result is hello2 but returns undefined
  20.         }
  21.     }
  22.  
  23. }
  24. </script>
Thanks
akadeco
Oct 3 '09 #1
2 1595
acoder
16,027 Expert Mod 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. alert(cells[1].getElementsByTagName('a')[0].innerHTML);
getElementsByTagName() returns a collection.
Oct 6 '09 #2
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.     var rows = document.getElementsByTagName('tr');
  3.     for (var i=0; i < rows.length; i++) {
  4.         var cells = rows[i].getElementsByTagName('td');
  5.         alert(cells[0].innerHTML);
  6.     }
  7. }
Is what I was after

Thanks
Oct 8 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matt Schroeder | last post by:
Does anyone know how to count how many rows are in a mysql table? This is what I have, but it doesn't work right: <? $db = mysql_connect("localhost", "username", "password");...
3
by: Steven | last post by:
Hi there, I have an admin system (Add/Modify/Delete) for two types of records in the database. They have a Parent - Child relationship My problem is that I want to display on the "parent"...
1
by: Lord Merlin | last post by:
How do I add up the values of the data from all of the rows returned? i.e - I have a DB, with 148 rows of client info, and I want to addup all the scores. Each entry's score differes. Here is the...
16
by: walexand | last post by:
I use the database mysql v.4. My problem is... I have a select like: select * from user where language = "de"; the result are then: id name =================== 1 max
3
by: Viswanatha Thalakola | last post by:
Hello, Can someone point me to getting the total number of inserts and updates on a table over a period of time? I just want to measure the insert and update activity on the tables. Thanks....
2
by: Adam | last post by:
In my MYISAM table I have an index (Index_A) on 2 fields (Field_A, Field_B). There are millions of rows in the table. The cardinality of Index_A is 53. I think a query to count the number of rows...
1
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for...
7
by: Patrick Olurotimi Ige | last post by:
I have a simple Stored Procedure with multiple select statements..doing select * from links for example. I created a DataTable and then fill the tables But the first dtTemplate DataTable doesn't...
1
osward
by: osward | last post by:
Hi all, I got code over the net for paging mysql table, it provides Prev pages Next link at the bottom of the table. However, I have a pretty large table to display (average over 400+ rows). Even...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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
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...
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...

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.