select an item in a listbox by value

i have a listbox on a form and I want to automatically select (i.e. highlight) one of the items using a javascript function
i will supply the value, but I'm not sure how to select the line based on the value, not the index
in the real world, the values in the select box below will be coming from a database and wont be sequential
so i need to select by value

<form name=thisForm id=thisForm>
<select name="S1" >
<option value=1>Choice 1</option>
<option value=2>Choice 2</option>
<option value=3>Choice 3</option>
<option value=4>Choice 4</option>
</select>

<SCRIPT LANGUAGE=javascript>
     document.thisForm.S1.???????=1
</SCRIPT>

</form>
LVL 13
bigbillydotcomAsked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
And to see it in blue add the focus method:
<SCRIPT LANGUAGE=javascript>
     document.thisForm.S1.value=3;
     document.thisForm.S1.focus();
</SCRIPT>

0
 
ZvonkoSystems architectCommented:
Like this:

<form name=thisForm id=thisForm>
<select name="S1" >
<option value=1>Choice 1</option>
<option value=2>Choice 2</option>
<option value=3>Choice 3</option>
<option value=4>Choice 4</option>
</select>

<SCRIPT LANGUAGE=javascript>
     document.thisForm.S1.value=1
</SCRIPT>

</form>

Freaking easy ;-)
0
 
bigbillydotcomAuthor Commented:
that doesnt actually select the option

i want to scroll the list and select that item by value
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
bigbillydotcomAuthor Commented:
when i say select - i want that choice highlighted
0
 
bigbillydotcomAuthor Commented:
in VB there was something like SelectByValue - but not sure how this is done in javascript
0
 
ZvonkoSystems architectCommented:
Put this and you will see that it is selected:

     document.thisForm.S1.value=3;

0
 
bigbillydotcomAuthor Commented:
GOTTA LOVE THE ZVONKO
Thats it bro - GREAT!
0
 
ZvonkoSystems architectCommented:
Uhps! Keep your temper! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.