Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#7889 closed bug (duplicate)

.val() not setting selected option

Reported by: fstani@… Owned by: fstani@…
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.

Change History (6)

comment:1 Changed 9 years ago by ajpiano

Owner: set to fstani@…
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.

comment:2 Changed 9 years ago by fstani@…

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.

comment:3 in reply to:  2 Changed 9 years ago by fstani@…

Replying to 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

comment:4 Changed 9 years ago by ajpiano

Resolution: duplicate
Status: newclosed

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

comment:5 Changed 9 years ago by ajpiano

Duplicate of #7863.

comment:6 Changed 8 years ago by elmastero74@…

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.

Note: See TracTickets for help on using tickets.