Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i make the particular item selected in select box using jquery on document load

iam having the select box

<select id ="myselect">
<option value="AA">AA</option>
<option value="AB">AB</option>
<option value="AC">AC</option>
<option value="AD">AD</option>
</select>

so on document load I want to Make item "AC" in the select box as the default selected option on loading the document

$('#myselect').children('option').text('AC').attr('selected', 'selected');

so with this statement written it is making my select box to fill with values 'AC' completely for my select box. How do i correct that and i tried in using the if statement comparing the value for 'AC'.And i dont have the "Value" for option as number

like image 712
Someone Avatar asked Jan 22 '23 08:01

Someone


1 Answers

It should be do-able with:

$('option[value=AC]').attr('selected','selected');

Demo at: jsbin.

like image 63
David Thomas Avatar answered Mar 08 '23 23:03

David Thomas