Page 1 of 1

IE can't access selectedIndex more then once?

Posted: Sat May 02, 2009 10:56 pm
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>

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

Posted: Sun May 03, 2009 12:19 am
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.