Skip to content Skip to sidebar Skip to footer

Set Selected Option

I've got option select. How to set as var selected select automaticly? E.g. I manually

Solution 1:

try this

$("#myOption").val("1");

Solution 2:

your code should be

<select><optionselected="selected">1</option><option>2</option></select>

Solution 3:

I agree with @creminsn!! and For that to get value Try this

var val;
$('#selectID').click(function(){
val=$('#selectID option:selected').val();
});

val will give you the selected val.And if you need text you can do

$('#selectID option:selected').text();

Solution 4:

I don't quite see what your issue is, however im getting the idea from what you've written that you want to submit the form upon the user selecting an option from the dropdown?

In which case u need JQuery to implement a listener (.live()) on the dropdown which will fire an event, in your case you want to submit the form (i think) so perhaps use .post() if you do want to use ajax.

look these up on the jQuery site.

Post a Comment for "Set Selected Option"