views:

42

answers:

1

I have a javascript function that works in IE7, but is giving me trouble in Firefox.

JAVASCRIPT

function vehicleSelected() {
   var ddlSelect = document.getElementById('ddlSelect');
   var displayTable = document.getElementsByName('listTable')[0];
   var strAuto = ddlSelect.options[ddlSelect.selectedIndex].value;
   alert("ok, so far");
   var rows = displayTable.getElementsByTagName("tr");
   alert("this alert is not triggered");
   var rowData = document.getElementById(strData);
   for (var i = 0; i < rows.length; i++) {
      rows[i].style.display = 'none';
   }
   rowData.style.display = '';
}

I am not sure how the rest of the code gets processed. Is there a universal way to toggle the display for a table row or do I need one for FIrefox separate?

EDIT

<table id="listTable">
A: 

your post leaves out a lot of details, but i'm guessing your html looks something like this

<table id='listTable' name='listTable'>

name is apparently not a valid attribute for a table (no mention here and visual studio intellisense agrees), so firefox ignores that attribute and does not find any elements named listTable. displayTable is undefined in the firefox execution.

internet explorer however, with it's neverending insistence for doing things wrong, sees that the id attribute has a value of 'listTable' and considers that good enough to qualify for getElementsByName. IE does not actually consider the name attribute you have given your table- it's just getting lucky. removing the id attribute will cause your method to fail in IE too.

lincolnk
That did help, but I am still stuck on how I would be able to call the table for use in the javascript. I made edits to display the table in the html
replace `document.getElementsByName('listTable')[0];` with `document.getElementById('listTable');`. this is the preferred way to do this anyway.
lincolnk