0

The JS starts with:

<script>
var tblId = 'TBGenericRecs0';
var nTable = "";


then later:
function mapTable(){

    nTable = document.getElementById(tblId);
    nRows = nTable.rows.length;

Firefox says nTable is not a function and the code does not work. IE sees it as a variable and it works. What's up? Is there a place to see what Javascript is acceptable for Firefox?

Edited by Reverend Jim: Fixed formatting

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by jb00786
0

I think you have an error someplace as I mocked this up and FF had no issues with nTable.rows.length. Try not initializing your nTable at the top as a string and just leave it var nTable; Also are you certain your code looking for table TBGenericRecs0' is running after the element exists on the page? It is likely that the script is trying to run in FF before the document is really ready. If you have firebug, try a console.log("nTable",nTable); before you attempt to grab the rows and see if you are getting the correct element.

0

THANK YOU!!! Is there a way to stall the JS until the page completes?

0

You could wrap everything in window.onload=function(){} or just use jQuery's ready function. The difference is for the jQuery option you will need to include the jQuery lib but all of you javascript can execute as soon as the DOM is created where the onload function will only fire once all page elements have loaded.
A nice explanation of what each will accomplish is provided in this link: http://api.jquery.com/ready/.

While JavaScript provides the load event for executing code when a page is rendered, this event does not get triggered until all assets such as images have been completely received. In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready

Either way here is a way to do it:

<script type=text/javascript>
window.onload = function()
{
   var tblId = 'TBGenericRecs0';
   var nTable;

   /*then later:*/
   function mapTable(){
      nTable = document.getElementById(tblId);
      nRows = nTable.rows.length;
   }
}
</script>

or using jQuery

<script type=text/javascript>
$(document).ready(function(){
   var tblId = 'TBGenericRecs0';
   var nTable;

   /*then later:*/
   function mapTable(){
      nTable = document.getElementById(tblId);
      nRows = nTable.rows.length;
   }

});
</script>

Edited by scrappedcola: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.