Bug Tracker

Opened 10 years ago

Closed 9 years ago

#5452 closed bug (fixed)

$('#select_element_id').val("") bug when its option has no value attribute in ie6/ie7

Reported by: Luckydog Owned by:
Priority: critical Milestone: 1.4
Component: core Version: 1.3.2
Keywords: select val ie6 ie7 Cc:
Blocked by: Blocking:

Description

In ie6/ie7, if option element has no value attribute, option_element.value property will return an empty string. And when I set an ampty string value to a select using $('#select_element_id').val(""), jquery will selected the last option of the select element. This bug occurs in line 471 in the source code of jquery-1.3.2.js.

Here is some sample code cause the bug.

<select id="select_element_id">

<option value="">ALL</option>

<option>Name1</option>

<option>Name2</option>

<option>Name3</option>

</select>

$('#select_element_id').val("");

Attachments (1)

test-5452.html (485 bytes) - added by dmethvin 10 years ago.
IE being stupid about option values

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by dmethvin

Attachment: test-5452.html added

IE being stupid about option values

comment:1 Changed 10 years ago by dmethvin

need: Test CasePatch

Confirmed; test case attached with slightly different conditions. I think the code in .val() is there both because IE6 doesn't support select.value and because multiple browsers don't handle select multiple properly if you use select.value.

comment:2 Changed 10 years ago by dservranckx@…

The same problem exists in IE8 with .val(0) as in $('#select_element_id').val(0) when trying to reset the selected index value to 0.

comment:3 Changed 9 years ago by dmethvin

Resolution: fixed
Status: newclosed

http://jsfiddle.net/dmethvin/wmhB5/

Seems to be working in 1.4.4

Note: See TracTickets for help on using tickets.