Ticket #1474 (closed bug: fixed)
setting selectedIndex doesn't update dropdown position
| Reported by: | eXcel | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.2 |
| Component: | core | Version: | 1.1.3 |
| Keywords: | form dropdown selectedIndex attr | Cc: | |
| Blocking: | Blocked by: |
Description
On my webpage, I noticed that if i did something like this
$('myDropdown').attr('selectedIndex',3);
the dropdown position would not change; however
alert($('myDropdown').attr('selectedIndex'));
prints 3
To see the correct behavior try something like this:
document.getElementById('myDropdown').selectedIndex = 3;
which does change the dropdown position
use with
<form> <select name="myDropdown" id="myDropdown"> <option value="a">a</option> <option value="b">b</option> <option value="c">c</option> <option value="d">d</option> <option value="e">e</option> <option value="f">f</option> </select> </form>
Tested in Firefox 2.0.0.6
Change History
comment:2 follow-up: ↓ 3 Changed 21 months ago by rosali
It looks like this bug is back again since jQuery 1.6.1.
comment:3 in reply to: ↑ 2 Changed 21 months ago by chiu0602+bugs_jquery@…
Replying to rosali:
It looks like this bug is back again since jQuery 1.6.1.
It happened on jQuery 1.6.2 too
comment:4 Changed 21 months ago by anonymous
Yep. It took me an hour of fiddling to finally realize that.
comment:5 follow-up: ↓ 6 Changed 21 months ago by dmethvin
Most likely you are using .attr() instead of .prop(). There is no *attribute* named selectedIndex so the code above is invalid.
comment:6 in reply to: ↑ 5 Changed 21 months ago by anonymous
Replying to dmethvin:
Most likely you are using .attr() instead of .prop(). There is no *attribute* named selectedIndex so the code above is invalid.
Using .prop doesn't change anything, still doesn't work.
comment:7 follow-up: ↓ 8 Changed 20 months ago by prakashsinha12@…
You Can get Selected index like this
$('myDropdown').get(0)('selectedIndex',3);
comment:8 in reply to: ↑ 7 Changed 18 months ago by anonymous
Replying to prakashsinha12@…:
You Can get Selected index like this
$('myDropdown').get(0)('selectedIndex',3);
When using an asp.net dropdownlist (<asp:DropDownList), when I tried to set a selectedIndex on the dropdownlist using the above example, it does not work.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Fixed in SVN Rev: [3387]