#6837 closed bug (fixed)
$(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 (5)
Changed 13 years ago by
Attachment: | jquery.html added |
---|
comment:1 Changed 12 years ago by
need: | Review → Patch |
---|---|
Priority: | → undecided |
comment:2 Changed 12 years ago by
Keywords: | needsreview added |
---|
comment:4 Changed 12 years ago by
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.