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.

Link to comment
Share on other sites

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>
.....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.