Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1236 How can I change the selected option when I only know the value of the option to be selected?

You are here: irt.org | FAQ | JavaScript | Form | Q1236 [ previous next ]

Enumerate the values:

<form name="myForm">
<select name="mySelect>
<option value="1">zero
<option value="x">one
<option value="qwerty">two
<option value="">three
</select>
</form>

<script language="JavaScript"><!--
for (var i=0;i<document.myForm.mySelect.options.length;i++) {
    if (document.myForm.mySelect.options[i].value == 'qwerty')
        document.myForm.mySelect.options[i].selected = true;
}
//--></script>

Feedback on 'Q1236 How can I change the selected option when I only know the value of the option to be selected?'

©2018 Martin Webb