Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - select option in select box [duplicate]

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.

like image 806
Eduard Luca Avatar asked Sep 13 '11 09:09

Eduard Luca


People also ask

How do you prevent duplicate selection in dropdown?

You also can remove the duplicates from the table list firstly, then create the drop down list. Select the column range you want to use in the table, the press Ctrl + C to copy it, and place it to another position by pressing Ctrl + V. Then keep selecting the list, click Data > Remove Duplicates.

How can we prevent duplicate values in multiple dropdown using jquery?

The below codes works fine for two dropdowns, but not for more than 2. var $select = $("select[id$='go']"); $select. change(function() { $select . not(this) .


1 Answers

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

$("#MySelectBox").val("5");
like image 152
njr101 Avatar answered Sep 19 '22 01:09

njr101