IE can't access selectedIndex more then once?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

IE can't access selectedIndex more then once?

Post by JAB Creations »

For some reason when I run this script in IE it works the first time but always fails on the second execution (and all others until you reload the page). Any one have any suggestions for getting around this please?

JavaScript

Code: Select all

alert(document.getElementById('meta_example').options[document.getElementById('meta_example').selectedIndex].getAttribute('title'));
HTML

Code: Select all

<select id="meta_example" name="meta_example">
 <option title="fiction" value="5">Fiction</option>
 <option title="forums" value="6">Forums</option>
 <option title="gallery" value="7">Gallery</option>
 <option title="gamer" value="8">Gamer</option>
 <option title="home" value="9">Home</option>
 <option title="music" value="10">Music</option>
 <option title="blog" value="3">News & Blog</option>
 <option title="philosophy" value="11">Philosophy</option>
 <option title="translations" value="12">Translations</option>
 <option title="web" value="13">Web</option>
</select>
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: IE can't access selectedIndex more then once?

Post by JAB Creations »

Well there were a couple duplicate ID's and I took care of them...and the problem still persisted! Well I am guessing that like ID's could trigger this too so I change the ID (added '123' at the end), adjusted the script, and it worked. Then I figured, ok is this an issue of cache? So I edited the ID back to it's original string and it works fine now. So if any one ever encounters the selectIndex working once and then failing the second time hopefully this will help out.
Post Reply