Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2011, 07:23 PM   PM User | #1
ravimagod
New to the CF scene

 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ravimagod is an unknown quantity at this point
Exclamation 'TypeError: xxx is not a function' is thrown only in Firefox

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
Code:
<!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
ravimagod is offline   Reply With Quote
Old 01-29-2011, 09:33 PM   PM User | #2
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
You're trying to call it like a function (with parentheses), but it isn't a function, hence the error.

What you really want to do is access the entries of an array-like object, and that you do with brackets:

Code:
alert(trows[i].id);
venegal is offline   Reply With Quote
Old 01-30-2011, 03:37 PM   PM User | #3
ravimagod
New to the CF scene

 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ravimagod is an unknown quantity at this point
Thumbs up Thanks It Worked

Hi

Thanks. It worked

Regards

Ravi
ravimagod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:28 AM.


Advertisement
Log in to turn off these ads.