#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: | |
Blocked by: | Blocking: |
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 (10)
comment:1 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 follow-up: 3 Changed 11 years ago by
It looks like this bug is back again since jQuery 1.6.1.
comment:3 Changed 11 years ago by
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:5 follow-up: 6 Changed 11 years ago by
Most likely you are using .attr()
instead of .prop()
. There is no *attribute* named selectedIndex
so the code above is invalid.
comment:6 Changed 11 years ago by
Replying to dmethvin:
Most likely you are using
.attr()
instead of.prop()
. There is no *attribute* namedselectedIndex
so the code above is invalid.
Using .prop doesn't change anything, still doesn't work.
comment:7 follow-up: 8 Changed 11 years ago by
You Can get Selected index like this
$('myDropdown').get(0)('selectedIndex',3);
comment:8 Changed 11 years ago by
Replying to [email protected]…:
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.
comment:9 Changed 11 years ago by
I have declare the asp:dropdownlist object as $("#<%=ddlCity.ClientID %>").get(0)('selectedIndex',3);
comment:10 Changed 9 years ago by
14/04/2014
$('#login').prop('selectedIndex', index);
this works for me :)
Fixed in SVN Rev: [3387]