Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  126] [ 5]  / answers: 1 / hits: 25002  / 12 Years ago, mon, april 2, 2012, 12:00:00

I have the following drop down list:



<select name=selSS1 id=select_value>
<option value=val0>sea zero</option>
<option value=val1>sea one</option>
<option value=val2>sea two</option>
<option value=val3>sea three</option>
<option value=val4>sea four</option>
</select>


I would like to dynamically select a value from that list using javascript:



I tried:



document.getElementById('select_value').selected =val3;


But the above code does not seem to work. Any help is most appreciated.


More From » javascript

 Answers
82

Use the following line:



 document.getElementById('select_value').value =val3;

or

document.getElementById('select_value').selectedIndex = 3;


Hope this solves ur problem.


[#86465] Saturday, March 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryley

Total Points: 118
Total Questions: 81
Total Answers: 102

Location: Kazakhstan
Member since Thu, Dec 23, 2021
3 Years ago
ryley questions
Thu, Sep 2, 21, 00:00, 3 Years ago
Wed, Feb 12, 20, 00:00, 4 Years ago
Wed, Oct 30, 19, 00:00, 5 Years ago
;