artworkad シ artworkad シ - 3 months ago 5x
jQuery Question

Set selected option of select box

I 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');


<select id="gate">
<option value='null'>- choose -</option>
<option value='Gateway 1'>Gateway 1</option>
<option value='Gateway 2'>Gateway 2</option>

But this does not work. Any ideas?


This definitely should work. Here's a demo. Make sure you have placed your code into a $(document).ready:

$(function() {
    $("#gate").val('Gateway 2');