| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|---|
| 2 | <head> |
|---|
| 3 | <title>Test</title> |
|---|
| 4 | <script type="text/javascript" src="jquery.js"></script> |
|---|
| 5 | <script type="text/javascript"> |
|---|
| 6 | $(function() { |
|---|
| 7 | var select = $('#select')[0]; |
|---|
| 8 | for (var i = 0; i < select.options.length; ++i) { |
|---|
| 9 | select.selectedIndex = i; |
|---|
| 10 | $(select).val($(select).val()); |
|---|
| 11 | $('body').append('<div>Testing selectedIndex === '+i+': '+(select.selectedIndex === i ? 'ok' : 'FAIL ['+select.selectedIndex+']')+'<'+'/div>'); |
|---|
| 12 | } |
|---|
| 13 | }); |
|---|
| 14 | </script> |
|---|
| 15 | </head> |
|---|
| 16 | <body> |
|---|
| 17 | <div> |
|---|
| 18 | First iteration through the loop sets selected=true for every option, since they all match val(''). |
|---|
| 19 | Firefox responds by selecting the first element only; IE selects the last. |
|---|
| 20 | Subsequent iterations work fine since val(x) uses a unique value each time. |
|---|
| 21 | </div> |
|---|
| 22 | <div> |
|---|
| 23 | <select id="select"> |
|---|
| 24 | <option></option> |
|---|
| 25 | <option>alpha</option> |
|---|
| 26 | <option>beta</option> |
|---|
| 27 | <option>gamma</option> |
|---|
| 28 | </select> |
|---|
| 29 | </div> |
|---|
| 30 | </body> |
|---|
| 31 | </html> |
|---|