Reputation: 223
I've got option select. How to set as var selected select automaticly?
<option>
<select>1</select>
<select>2</select>
</option>
E.g. I manually select option 1, and it automaticly is
<select selected="selected">1</select>
EDIT I found out.
<select id="sel">
<option value="1">aa</option>
<option value="2">bb</option>
<option value="3">cc</option>
</select>
$("#sel").change(function(){
alert($(this).val())
});
Upvotes: 0
Views: 2206
Reputation: 2748
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.
Upvotes: 0
Reputation: 639
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();
Upvotes: 0
Reputation: 9200
your code should be
<select>
<option selected="selected">1</option>
<option>2</option>
</select>
Upvotes: 1