Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#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:


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'


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)

jquery.html (934 bytes) - added by vortfu 13 years ago.

Download all attachments as: .zip

Change History (5)

Changed 13 years ago by vortfu

Attachment: jquery.html added

comment:1 Changed 12 years ago by addyosmani

need: ReviewPatch
Priority: undecided

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.

comment:2 Changed 12 years ago by snover

Keywords: needsreview added

comment:3 Changed 12 years ago by snover

Milestone: 1.4.3

Resetting milestone to future.

comment:4 Changed 12 years ago by timmywil

Milestone: 1.5
Priority: undecidedhigh
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.