473,789 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting links in table rows

7 New Member
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 1613
acoder
16,027 Recognized Expert Moderator MVP
Try:
Expand|Select|Wrap|Line Numbers
  1. alert(cells[1].getElementsByTagName('a')[0].innerHTML);
getElementsByTa gName() returns a collection.
Oct 6 '09 #2
akadeco
7 New Member
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
18671
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"); mysql_select_db("database",$db); $sql = "SELECT COUNT(*) FROM table"; $result = mysql_query($sql); echo "$result"; ?>
3
1737
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" record whether the child exists or not . The records are found in two different tables, but have the same Primary Key.
1
1253
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 code I have sofar: SQL = "select * from company_scores order by company_name" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.CursorLocation = adUseServer objRS.CursorType = adOpenStatic objRS.ActiveConnection = objConn
16
1734
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
3055
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. - Vish
2
1761
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 that match a pair of values for Field_A and Field_B should execute blindingly fast (in the index count the number of leaf nodes for the B-Tree node representing the indexed pair of values). My query looks like: SELECT count(*) FROM `table_A`...
1
1966
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 the first page): display the section name, the current file and a few archive files. If there is more than a page full (for each additional page): display the section name, and the next set of archive files.
7
1701
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 give the error but the links does! I get the error on this LINE(when looping):- PageLinks.Text = PageLinks.Text & dtLinks.Rows(iLoop)("link_url")
1
1787
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 when I limited the rows to display 30, It still have over 10 page link display between Prev and Next link. Following are code to display the links echo "<center>"; // Build First & Previous page Link if($page > 1){ $prev = ($page -...
0
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10193
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
10136
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
9979
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
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6761
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4089
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
3
2906
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.