Bug Tracker

Opened 15 years ago

Closed 12 years ago

#3104 closed bug (worksforme)

setting a value on a select element ambiguous

Reported by: Borre Owned by:
Priority: major Milestone: 1.4.3
Component: attributes Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:


given a select box:

<select id="test_dropdown">
  <option value="1">somevalue</option>
  <option value="2">1</option>

and given the statement


the second option will be selected. This seems to be unwanted behaviour (in my opinion, an option with a value attribute should have priority). The erroneous code seems to be located in jquery-1.2.6.js on line 419:

jQuery( "option", this ).each(function(){
	this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
	jQuery.inArray( this.text, values ) >= 0);

Change History (5)

comment:1 Changed 14 years ago by laurenty

I confirm this unwanted behavior. As per W3 standard regarding the 'value' attribute of OPTION:

"This attribute specifies the initial value of the control. If this attribute is not set, the initial value is set to the contents of the OPTION element."

comment:2 Changed 14 years ago by john

Resolution: fixed
Status: newclosed

It sounds like this was fixed in jQuery 1.3.

comment:3 Changed 14 years ago by Borre

Resolution: fixed
Status: closedreopened

I'm sorry to say it was not. The problem still exists.

The solution that works for me is replacing jquery-1.3.1.js, line 462-465:

jQuery( "option", this ).each(function(){
	this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
	jQuery.inArray( this.text, values ) >= 0);


var selectedFound = false;
jQuery( "option", this ).each(function(){
	selectedFound = selectedFound || (this.selected = (jQuery.inArray( this.value, values ) >= 0));

	jQuery( "option", this ).each(function(){
		this.selected = (jQuery.inArray( this.text, values ) >= 0);

comment:4 Changed 13 years ago by dmethvin

Component: coreattributes

comment:5 Changed 12 years ago by john

Resolution: worksforme
Status: reopenedclosed

This was resolved in 1.4. More tests here to confirm: http://github.com/jquery/jquery/commit/879799fe955f01b85b59fd8a0096d415fc48df03

Note: See TracTickets for help on using tickets.