I have one slect box with various options.
I want that when page loads then one option with value e,g 10 should be preselected with jquery
how can i do that
thanks
I have one slect box with various options.
I want that when page loads then one option with value e,g 10 should be preselected with jquery
how can i do that
thanks
Test the example: http://jsfiddle.net/VArCZ/
$(document).ready(function() {
$('#mySelectBox').val('10');
});
Although, jQuery wouldn't be required for this if the intial value will be static:
<select id='mySelectBox'>
<option value='5'>5</option>
<option value='10' selected='selected'>10</option>
<option value='15'>15</option>
</select>
When the page loads run this (you can put it in <body onload="//put code here">):
$("option[value='10']").attr('selected','selected');