user979331
user979331

Reputation: 11861

Jquery get the selection option in select

I am trying to select a certain value in my dropdown via jquery..I tried this..

$("#membershiptype").val(1).selected;

it doesnt work..I am clearly over my head here as I am inexperience in jquery.

Upvotes: 0

Views: 57

Answers (2)

Denys Séguret
Denys Séguret

Reputation: 382150

To select an option by index, you can do this :

$("#membershiptype").get(0).selectedIndex=1;

Demonstration

To select an option by value (the content of the option), you may use this :

$("#membershiptype").val('B');​

Demonstration

Upvotes: 2

Usha
Usha

Reputation: 1468

You can assign the val() to the option value you want to be selected.

$('#membershiptype').val(valueToBeSelected);

Upvotes: 0

Related Questions