Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Two Values in a Multiple List Box

Status
Not open for further replies.

lee2k

Programmer
Aug 19, 2001
28
IN
hi,

in a form named "f1" i have a multiple list box named "m1" with ten values such as "one","two","three",...."ten". if i click a button then "three","five" and, "Seven" should be selected.
i want to write such a function in javascript.

hope anyone will help me in this regard..

lenin
 
okay, this is how it works:

you have a form with a select box in it:
Code:
<form name=f1>
<select size=7 name=sel multiple>
<option>#1
<option>#2
<option>#3
<option>#4
<option>#5
<option>#6
<option>#7
<option>#8
</select>
</form>

now, think of the select box not only as an html element, but as a js array also.

you can refrence each option by using:
Code:
document.f1.sel.options[x]
(where x is some value)

then, each option has its own set of read-write variables:
value, text, selected, and probably some more

so, if you wanted to select option #6, use
Code:
document.f1.sel.options[5].selected=true;

that should help, I hope I didnt bore you with a long explanaition theEclipse
eclipse_web@hotmail.com
**\\||It was recently discovered that research causes cancer in rats||//**
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top