Side navigation
#6837 closed bug (fixed)
Opened July 28, 2010 02:20AM UTC
Closed April 15, 2011 03:24AM UTC
Last modified March 09, 2012 02:59AM UTC
$(selectElement).val() will return nothing after a form reset in IE
Reported by: | vortfu | Owned by: | |
---|---|---|---|
Priority: | high | Milestone: | 1.5 |
Component: | attributes | Version: | 1.4.2 |
Keywords: | internet explorer val select reset needsreview | Cc: | |
Blocked by: | Blocking: |
Description
In Internet Explorer, calling val() on a select element (where type = select-one and none of the child option elements being explicitly defined as being selected) after a form reset will result in an empty value being returned instead of the value of the default/first option.
The problem appears to be that IE will set selectElement.selectedIndex correctly, but not set selectElement.options[selectElement.selectedIndex].selected after a reset.
A suggested patch which fixes this issue would be to check against selectedIndex instead of just option.selected if type == 'select-one'
ie:
src/attributes.js
~line 85
Loop through all the selected options
for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
var option = options[ i ];
if ( option.selected || ( one && index == i ) ) {
Get the specifc value for the option
value = jQuery(option).val();
We don't need an array for one selects
if ( one ) {
return value;
}
Multi-Selects return an array
values.push( value );
}
}
demo file attached.
Attachments (1)
Change History (4)
Changed October 04, 2010 06:13AM UTC by comment:1
need: | Review → Patch |
---|---|
priority: | → undecided |
Changed October 18, 2010 12:40AM UTC by comment:2
keywords: | internet explorer val select reset → internet explorer val select reset needsreview |
---|
Changed November 12, 2010 02:39AM UTC by comment:3
milestone: | 1.4.3 |
---|
Resetting milestone to future.
Changed April 15, 2011 03:24AM UTC by comment:4
milestone: | → 1.5 |
---|---|
priority: | undecided → high |
resolution: | → fixed |
status: | new → closed |
Tested the above bug in both IE6, IE8 and IE9. The behaviour is that as mentioned IE fails to return the correct value of the default/first item in the select after a form reset, instead returning an empty string.
Recommending a review and patch.