Row Numbers in Firefox

A

Angel

How do I find the row & column number of the table for a checkbox on
its Onclick event

The following HTML sample works perfect in IE. On click of the
checkboxes, I am displaying the row number and its column number. How
do I manage the same in Firefox?


<html>
<head>
<script language="javascript">
function selectedRow(object,cNumber)
{
while (object.tagName != 'TR')
{
object = object.parentNode;
}
RowNumber = object.rowIndex;
cellNumber = cNumber;
alert(RowNumber + " : " + cellNumber)
}
</script>
</head>


<body>
<table width="20%" border="1" cellpadding="0" cellspacing="0"
bordercolor="#CCCCCC" id=myTable name=myTable>
<tr id="1">
<td width="28%"><input name="r1c1" type="checkbox" id="r1c1"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R1, C1</td>
<td width="32%"><input name="r1c2" type="checkbox" id="r1c2"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R1, C2</td>
</tr>
<tr id="1">
<td><input name="r2c1" type="checkbox" id="r2c1"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R2, C1</td>
<td><input name="r2c1" type="checkbox" id="r2c1"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R2, C1</td>
</tr>
</table>
</body>
</html>
 
T

TheBagbournes

Angel said:
How do I find the row & column number of the table for a checkbox on
its Onclick event

The following HTML sample works perfect in IE. On click of the
checkboxes, I am displaying the row number and its column number. How
do I manage the same in Firefox?


<html>
<head>
<script language="javascript">
function selectedRow(object,cNumber)
{
while (object.tagName != 'TR')
{
object = object.parentNode;
}
RowNumber = object.rowIndex;
cellNumber = cNumber;
alert(RowNumber + " : " + cellNumber)
}
</script>
</head>


<body>
<table width="20%" border="1" cellpadding="0" cellspacing="0"
bordercolor="#CCCCCC" id=myTable name=myTable>
<tr id="1">
<td width="28%"><input name="r1c1" type="checkbox" id="r1c1"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R1, C1</td>
<td width="32%"><input name="r1c2" type="checkbox" id="r1c2"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R1, C2</td>
</tr>
<tr id="1">
<td><input name="r2c1" type="checkbox" id="r2c1"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R2, C1</td>
<td><input name="r2c1" type="checkbox" id="r2c1"
onClick="selectedRow(this.parentElement,this.parentNode.cellIndex)">
R2, C1</td>
</tr>
</table>
</body>
</html>

You have "this.parentElement" in the onclick method. You mean
"this.parentNode".

Nige
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top