IE Javascript problem?
|  | The article you are reading has moved! It is now available at: http://blog.tinisles.com/2006/05/ie-javascript-problem/ | 
What would you expect the bit of javascript below to do?
<html>
<body>
    <select id="testing">
    </select>
    <script>
        var testing = document.getElementById('testing');
            
        var georgeOpt = new Option("George", 1);
        testing.options[testing.length]=georgeOpt;        
        
        var paulOpt = new Option("Paul", 2);
        testing.options[testing.length]=paulOpt;    
            
        var johnOpt = new Option("John", 3);
        testing.options[testing.length]=johnOpt;    
            
        var ringoOpt = new Option("Ringo", 4);
        ringoOpt.selected = true;
        testing.options[testing.length]=ringoOpt;        
    </script>
</body>
</html>
In Firefox the SELECT is displayed with Ringo selected, in IE John is selected. If you swap the last two lines of script - Ringo is selected in both browsers. Easily fixed so its no biggie. I guess it doesn't really make sense to tell an OPTION it is selected before it belongs to a SELECT?
Labels: javascript

