Skip to main content

Bug Tracker

Side navigation

#7889 closed bug (duplicate)

Opened January 03, 2011 06:56PM UTC

Closed January 04, 2011 01:30PM UTC

Last modified June 11, 2012 04:21PM UTC

.val() not setting selected option

Reported by: fstani@gmail.com Owned by: fstani@gmail.com
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

.val() when used to set an option selected in a select element fails in chrome.

Using $("#selectId").val("test");

<select>

<option value="default">FIRST</option>

<option value="test">SECOND</option>

</select>

Works on jQuery 1.4.2, and 1.4.3, but doesn't work on 1.4.4.

The Second option is not selected.

Attachments (0)
Change History (6)

Changed January 03, 2011 07:18PM UTC by ajpiano comment:1

owner: → fstani@gmail.com
status: newpending

In the future, please follow the instructions in the red box and file a testcase on jsFiddle that duplicates the error you're having.

I went ahead and created a testcase that works just fine in Chrome on jQuery 1.4.4: http://jsfiddle.net/ajpiano/KhnFw/

If you can provide a testcase that actually shows this failing, we'll be happy to investigate further.

Changed January 04, 2011 10:58AM UTC by fstani@gmail.com comment:2

status: pendingnew

Hi sorry about that, unfortunately I only read the part about jsFiddle later.

Anyways, here is the problem in jsFiddle.

http://jsfiddle.net/cdDWm/1/

As you can see in this case, using jQuery 1.4.4 the value of the select stays the same, but if you use jQuery 1.4.3 or below the value is changed.

Changed January 04, 2011 11:02AM UTC by fstani@gmail.com comment:3

Replying to [comment:2 fstani@…]:

Hi sorry about that, unfortunately I only read the part about jsFiddle later. Anyways, here is the problem in jsFiddle. http://jsfiddle.net/cdDWm/1/ As you can see in this case, using jQuery 1.4.4 the value of the select stays the same, but if you use jQuery 1.4.3 or below the value is changed.

BTW I did a little fiddling with your own script and it seems that the problem is using an id with . in it.

http://jsfiddle.net/KhnFw/1/

As you can see using foo.bar as the select id, and using the escape notation for the ., only works in 1.4.3 (below), at 1.4.4 it seems to be either broken or with a different behavior.

Best regards,

Fabio

Changed January 04, 2011 01:30PM UTC by ajpiano comment:4

resolution: → duplicate
status: newclosed

This bug is already fixed in the jQuery GIT 0 version, which you can test in jsFiddle.

Changed January 04, 2011 01:30PM UTC by ajpiano comment:5

Duplicate of #7863.

Changed June 11, 2012 04:21PM UTC by elmastero74@gmail.com comment:6

This seems to still be a problem in 1.5.2 as well.

http://jsfiddle.net/CXF4K/47/

^^Click on an image and firebug the dropdown. Notice that no 'selected' attribute gets set.

Works fine in 1.6.4. See here: http://jsfiddle.net/CXF4K/48/

^^ Do the same thing here and it works.