-1
<select style="display: none;" name="subcat" class="option" id="id2">
    <option value="1">General</option><option value="2">Category 1</option>
    <option value="3">Category 2</option>
</select>

One line code that sets the option value 2. Not a tough question though I spent two hours in doing that and really frustrated. Please make sure it is tested. Thanks!

  • Possible duplicate of [How do I programmatically set the value of a select box element using javascript?](http://stackoverflow.com/questions/78932/how-do-i-programmatically-set-the-value-of-a-select-box-element-using-javascript) – Andreas Jul 12 '16 at 15:44
  • "Please make sure it is tested." Really? Show us what you've tried. – Bek Jul 12 '16 at 15:46
  • I have two select boxes having the same options. Desired is if I select the first select box option (any option) and click a button then the same option reflect in the other select box. – Himanshu Shekhar Jul 12 '16 at 15:47
  • @Bek http://stackoverflow.com/questions/38330852/populate-same-one-selected-value-to-other-multiple-select-boxes-using-jquery – Himanshu Shekhar Jul 12 '16 at 15:49

1 Answers1

0

You can try the below methods

$(".option").val('2');

OR

$('.option').prop('selectedIndex', 2); 
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41