0

I have the following drop-down:

<select id="#test">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

Now I am getting a value on document.ready like:

var res = $('#someotherid').val();

which is 1,2 or 3.

Now I want this value automatically set in the drop-down.

Does anyone know how to do this?

Luwe
  • 3,026
  • 1
  • 20
  • 21
Hitu Bansal
  • 5
  • 1
  • 5
  • Possible duplicate of http://stackoverflow.com/questions/7399640/jquery-select-option-in-select-box/7399694#7399694 – njr101 Sep 16 '11 at 08:13

1 Answers1

1

You can set the selected option with the val method too, so after you get the value of whatever #someotherid is, you can use it to set the selected option of #test:

var res= $('#someotherid').val();
$("#test").val(res);

Here's a working example.

James Allardice
  • 164,175
  • 21
  • 332
  • 312