ravimagod
01-29-2011, 07:23 PM
Hi
I am trying to go through rows of table using
var table= document.getElementById('table');
var trows = table.getElementsByTagName('tr');
I am able run through the table and review each row in IE, Chrome it works perfectly. The same code when viewed in FireFox throws 'TypeError: trows is not a function' error. The error occurs when I try to get the row id by using 'trows(i).id' while 'trows.length' works fine.
I am foxed!! Any way to get over this.
The code HTML page is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Firefox Error</title>
<script type="text/javascript">
function checkTable(){
var table= document.getElementById('table');
var trows = table.getElementsByTagName('tr');
for (var i= 0; i < trows.length; i++) {
try{
alert(trows(i).id);
}
catch(e){
alert(e);
}
}
}
</script>
</head>
<body onload="checkTable();">
<table id="table">
<tr id="tr1">
<td>Trial1</td>
<td>Trial2</td>
</tr>
<tr id="tr2">
<td>Trial4</td>
<td>Trial5</td>
</tr>
<tr id="tr3">
<td>Trial6</td>
<td>Trial7</td>
</tr>
<tr id="tr4">
<td>Trial11</td>
<td>Trial21</td>
</tr>
</table>
</body>
</html>
Thanks
Ravi
I am trying to go through rows of table using
var table= document.getElementById('table');
var trows = table.getElementsByTagName('tr');
I am able run through the table and review each row in IE, Chrome it works perfectly. The same code when viewed in FireFox throws 'TypeError: trows is not a function' error. The error occurs when I try to get the row id by using 'trows(i).id' while 'trows.length' works fine.
I am foxed!! Any way to get over this.
The code HTML page is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Firefox Error</title>
<script type="text/javascript">
function checkTable(){
var table= document.getElementById('table');
var trows = table.getElementsByTagName('tr');
for (var i= 0; i < trows.length; i++) {
try{
alert(trows(i).id);
}
catch(e){
alert(e);
}
}
}
</script>
</head>
<body onload="checkTable();">
<table id="table">
<tr id="tr1">
<td>Trial1</td>
<td>Trial2</td>
</tr>
<tr id="tr2">
<td>Trial4</td>
<td>Trial5</td>
</tr>
<tr id="tr3">
<td>Trial6</td>
<td>Trial7</td>
</tr>
<tr id="tr4">
<td>Trial11</td>
<td>Trial21</td>
</tr>
</table>
</body>
</html>
Thanks
Ravi