How to add a title in html select tag
http://stackoverflow.com/questions/18179960/how-to-add-a-title-in-html-select-tag<select>
<option selected disabled>Choose one</option>
<option value="sydney">Sydney</option>
<option value="melbourne">Melbourne</option>
<option value="cromwell">Cromwell</option>
<option value="queenstown">Queenstown</option>
</select>
How to set default value for HTML select element?
http://stackoverflow.com/questions/3518002/how-to-set-default-value-for-html-select-element<select name="hall" id="hall">
<option> 1 </option>
<option> 2 </option>
<option selected> 3 </option>
<option> 4 </option>
<option> 5 </option>
</select>
Set selected option of select box
http://stackoverflow.com/questions/4680075/set-selected-option-of-select-boxI want to set a option that was selected previously to be displayed on page load. I tried it with the following code:
$("#gate").val('Gateway 2');
with
<select id="gate">
<option value='null'>- choose -</option>
<option value='Gateway 1'>Gateway 1</option>
<option value='Gateway 2'>Gateway 2</option>
</select>
But this does not work. Any ideas?
Answer: This definitely should work. Here's a demo. Make sure you have placed your code into a $(document).ready
:
$(function() {
$("#gate").val('Gateway 2');
});