Bug Tracker

Opened 10 years ago

Closed 10 years ago

#9926 closed bug (worksforme)

set value to select element

Reported by: gd_lzg@… Owned by: gd_lzg@…
Priority: low Milestone: None
Component: manipulation Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:


code about below: <select id="test"> <option value="13">11</option> <option value="11">aa</option> <select> when i use $("#test").val("11") to set value to select element,the selected one is <option value="13">11</option> but not <option value="11">aa</option>

Change History (3)

comment:1 Changed 10 years ago by anonymous

my jquery version is 1.3.2

comment:2 Changed 10 years ago by ajpiano

Owner: set to gd_lzg@…
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced jsFiddle test case to help us assess your ticket! Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists - we do not solve bugs that exist only in jQuery 1.3.2 if they have since been addressed. To get you started, we've created this boilerplate: http://jsfiddle.net/rwaldron/da3nM/ Open the link and click to "Fork" in the top menu.

comment:3 Changed 10 years ago by addyosmani

Component: unfiledmanipulation
Priority: undecidedlow
Resolution: worksforme
Status: pendingclosed

I've put together a working test case based on the code you supplied here: http://jsfiddle.net/Gn2fF/1/. Please remember that the code you're using will set the selected option to the item with the *value* of 11, not the text '11'. To set the other item to be selected, simply use .val(13) in your test case instead. If you require further assistance with understanding the differences between setting selected elements based on option values or inline text values, please feel free to ask for assistance in the #jquery channel on freenode.

Note: See TracTickets for help on using tickets.