Bug Tracker

Modify

Ticket #6837 (closed bug: fixed)

Opened 4 years ago

Last modified 2 years ago

$(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:
Blocking: Blocked by:

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

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

Change History

Changed 4 years ago by vortfu

comment:1 Changed 4 years ago by addyosmani

  • need changed from Review to Patch
  • Priority set to 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 3 years ago by snover

  • Keywords needsreview added

comment:3 Changed 3 years ago by snover

  • Milestone 1.4.3 deleted

Resetting milestone to future.

comment:4 Changed 3 years ago by timmywil

  • Priority changed from undecided to high
  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone set to 1.5

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.