You are here: irt.org | FAQ | JavaScript | Form | Q1598 [ previous next ]
Try the following for a single select list:
<form name="myForm">
<select name="mySelect">
<option>abc
<option>xyz
<option>abc
<option>xyz
<option>abc
<option>xyz
<option>abc
<option>xyz
</select>
</form>
<script language="JavaScript"><!--
function selectIt(txt) {
theSel = document.myForm.mySelect;
for (i=0;i<theSel.options.length) {
if (theSel.options[i].text == txt) {
theSel.selectedIndex = i;
break;
}
}
}
//--></script>And the following for a multiple select list:
<form name="myForm">
<select name="mySelect" multiple size="3">
<option>abc
<option>xyz
<option>abc
<option>xyz
<option>abc
<option>xyz
<option>abc
<option>xyz
</select>
</form>
<script language="JavaScript"><!--
function selectIt(txt) {
theSel = document.myForm.mySelect;
for (i=0;i<theSel.options.length) {
if (theSel.options[i].text == txt) {
theSel.options[i].selected = true;
}
}
}
//--></script>