Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  160] [ 4]  / answers: 1 / hits: 80299  / 13 Years ago, tue, september 13, 2011, 12:00:00

Possible Duplicate:

jQuery / Programmatically Select an Option in Select Box






I was wondering, is it possible to select an option from a selectbox/combobox directly from jQuery. For example I want to select the option with the value 5 in a select with values from 1 to 10.



The only solution I can think of is to remove all options and recreate them with the right selected value, but that's a bit unefficient.


More From » jquery

 Answers
10

Just treat the select box as you would any other input element:



$(#MySelectBox).val(5);

[#90125] Sunday, September 11, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
susand

Total Points: 690
Total Questions: 101
Total Answers: 104

Location: Lesotho
Member since Wed, Jun 2, 2021
3 Years ago
;