Jump to content

[SOLVED] Select box element.options[element.selectedIndex] JS error in IE not Firefox


Rottingham

Recommended Posts

I have a PHP page that includes a <select> box, with a function to refresh the page when you click on a different option. For some reason, the JS script reports on error on IE and works perfectly in Firefox. I test each stage of my development between both for compatibility, but this is driving me nuts.

 

function change_family(elem_id)
{
     var elem = document.getElementById(elem_id);
     var elem_options = document.getElementById(elem_id).options;
     var family_id = elem.selectedIndex;
     family_id = elem.options[family_id].value;

     window.location="family.php?search&view="+family_id;
}

 

The Database ID of the family is stored in the <option value="[iD]"> field. So when change_family is called, it gets that ID number and refreshes the page.

 

The problem is that IE reports: 'options' is null or not an object. In firefox, it works GREAT! And so far, I have many many JS scripts that do near identical steps, and it works find in IE and Firefox. Any outsiders looking in have good idea what the problem is?

 

Thanks a ton.

That's way too much code, the select menu have the value of it's selected option. You can do something like this

<select onchange="location.href='family.php?search&view='+this.value;">
<option value="[iD]">option</option>
.....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.