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?

Recommended Answers

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 …

Jump to Post

All 4 Replies

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.

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

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>

You Rock! Sincerely Thank You!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.