Skip to main content

Bug Tracker

Side navigation

#1474 closed bug (fixed)

Opened August 08, 2007 01:21AM UTC

Closed September 18, 2007 02:36PM UTC

Last modified April 14, 2014 08:28AM UTC

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

Attachments (0)
Change History (10)

Changed September 18, 2007 02:36PM UTC by brandon comment:1

resolution: → fixed
status: newclosed

Fixed in SVN Rev: [3387]

Changed August 23, 2011 04:06AM UTC by rosali comment:2

It looks like this bug is back again since jQuery 1.6.1.

Changed August 26, 2011 02:54PM UTC by chiu0602+bugs_jquery@gmail.com comment:3

Replying to [comment:2 rosali]:

It looks like this bug is back again since jQuery 1.6.1.

It happened on jQuery 1.6.2 too

Changed August 26, 2011 05:18PM UTC by anonymous comment:4

Yep. It took me an hour of fiddling to finally realize that.

Changed August 26, 2011 05:29PM UTC by dmethvin comment:5

_comment0: Most likely you are using `.attr()` instead of `.prop()`.1314379781414770

Most likely you are using .attr() instead of .prop(). There is no *attribute* named selectedIndex so the code above is invalid.

Changed September 03, 2011 12:23PM UTC by anonymous comment:6

Replying to [comment:5 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.

Changed September 14, 2011 06:40AM UTC by prakashsinha12@gmail.com comment:7

You Can get Selected index like this

$('myDropdown').get(0)('selectedIndex',3);

Changed November 17, 2011 09:18AM UTC by anonymous comment:8

Replying to [comment:7 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.

Changed November 17, 2011 09:20AM UTC by dermotmcevoyrockey@gmail.com comment:9

I have declare the asp:dropdownlist object as

$("#<%=ddlCity.ClientID %>").get(0)('selectedIndex',3);

Changed April 14, 2014 08:28AM UTC by anonymous comment:10

14/04/2014

$('#login').prop('selectedIndex', index);

this works for me :)