Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for November 2012

Use jQuery select an option from dropdown

leave a comment »

Self note

<select id="target">
<option selected>--- blank</option>
<option value="21">test1</option>
<option value="12">test2</option>
<option value="30">test3</option>
</select>

Using index:

  $('#target>option:eq(1)').attr('selected', true);
  // test1 will be select

Or select by value:

  $(#target>option[value=30]').attr('selected', true);
  // test3 will be select

 

Advertisements

Written by Chorn Sokun

November 11, 2012 at 12:02 pm