Ticket #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: | ||
| Blocking: | Blocked by: |
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
comment:2 follow-up: ↓ 3 Changed 2 years ago by fstani@…
- Status changed from pending to new
Hi sorry about that, unfortunately I only read the part about jsFiddle later.
Anyways, here is the problem in jsFiddle.
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 2 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.
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.
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 2 years ago by ajpiano
- Status changed from new to closed
- Resolution set to duplicate
This bug is already fixed in the jQuery GIT 0 version, which you can test in jsFiddle.
comment:6 Changed 12 months ago by elmastero74@…
This seems to still be a problem in 1.5.2 as well.
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.