Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form | Q1236 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.