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

this.rowIndex question

Folks,

Can someone please tell me why this simple piece of code, irritatingly,
fails to give the expected result?

Regards
Rae MacLeman

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Sample Code</title>
</head>
<body>
<table id="table1" border="1">
<tr>
<td onClick="alert(this.rowIndex);">Tell me which row</td>
</tr>
<tr>
<td onClick="alert(this.rowIndex);">Tell me which row</td>
</tr>
<tr>
<td onClick="alert(this.rowIndex);">Tell me which row</td>
</tr>
</table>
</body>
</html>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04
Jul 23 '05 #1
4 9443
On Sun, 10 Oct 2004 18:45:23 +0100, webdev <so*****@microsofdt.com> wrote:
Can someone please tell me why this simple piece of code, irritatingly,
fails to give the expected result?
[snip]
<td onClick="alert(this.rowIndex);">Tell me which row</td>


[snip]

Table cells don't have a rowIndex property, rows do.

onclick="alert(this.parentNode.rowIndex);"

retrieves the containing row, and its index within the table.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
webdev wrote:
Can someone please tell me why this simple piece of code,
irritatingly, fails to give the expected result?
Not unless you state what your expectation is. I would be expecting the
alerts to report "undefined" or fail to operate (having no string
argument) depending on the browser.

<snip><tr>
<td onClick="alert(this.rowIndex);">Tell me which row</td>
</tr>

<snip>

Are you expecting the TD elements to have a rowIndex property? If you
are interested in the rowIndex of the containing TR you might try -
this.parentNode.rowIndex -.

Richard.
Jul 23 '05 #3

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:ck*******************@news.demon.co.uk...
webdev wrote:
Can someone please tell me why this simple piece of code,
irritatingly, fails to give the expected result?


Not unless you state what your expectation is. I would be expecting the
alerts to report "undefined" or fail to operate (having no string
argument) depending on the browser.

<snip>
<tr>
<td onClick="alert(this.rowIndex);">Tell me which row</td>
</tr>

<snip>

Are you expecting the TD elements to have a rowIndex property? If you
are interested in the rowIndex of the containing TR you might try -
this.parentNode.rowIndex -.

Richard.

My expectation was that it would return the rowindex ;0)

I'm wiser now

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04
Jul 23 '05 #4

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsfn1pun6x13kvk@atlantis...
On Sun, 10 Oct 2004 18:45:23 +0100, webdev <so*****@microsofdt.com> wrote:
Can someone please tell me why this simple piece of code, irritatingly,
fails to give the expected result?


[snip]
<td onClick="alert(this.rowIndex);">Tell me which row</td>


[snip]

Table cells don't have a rowIndex property, rows do.

onclick="alert(this.parentNode.rowIndex);"

retrieves the containing row, and its index within the table.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


Thanks Mike - I'd already tried "parentNode.rowIndex" somewhere along the
line.

Rae
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04
Jul 23 '05 #5

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

Similar topics

4
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
7
by: meaneyedcat | last post by:
When I call addField(), my table appears to be populated correctly with a new row in the table with all the required fields. However, when I call delete row on any new rows that have been created,...
2
by: amelia170 | last post by:
I am creating a database with a yes or no answer for question 1. Based on that answer, (if they answer yes) they will answer question 2, then three....However, if they answer no to question one, I...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
5
by: Paul Smith | last post by:
I am sorry but this is killing me..... On one page I have a DropDownList from which the user makes a selection. This is then passed to another page as a Request variable. On the load of the...
6
by: Carlos | last post by:
Hi all, ca anybody help me to translate to vb .net this c# instruction? string fname = ((TextBox)GridView1.Rows. Cells.Controls).Text; Thanks, Carlos
3
by: =?Utf-8?B?aG5nbzAx?= | last post by:
All, I have 2 questions: 1 - i am using DataAdapter to fill my dataset and then feed my dataset to my Datagridview to display data on my form. Why it takes little slow to display about 10,000...
1
by: itsvineeth209 | last post by:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Description: An unhandled exception occurred during the execution of the current web...
4
by: Jonathan Wood | last post by:
I'm having problems with the following code, which is an event handler for a GridView control: protected void grdWorkout_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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
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
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...

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.