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

Q887 How can I use the value of a select form field on the same page without submitting the form?

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

Try the following which places the selected options value and text value in two global JavaScript variables:

<script language="JavaScript"><!--
var selectedOptionValue = null;
var selectedOptionText = null;

function changed(what) {
    selectedOptionValue = what.options[what.selectedIndex].value;
    selectedOptionText = what.options[what.selectedIndex].text;
}
//--></script>

<form onSubmit="return false">
<select onChange="changed(this)">
<option value="first value">first text
<option value="second value">second text
</select>
</form>

Feedback on 'Q887 How can I use the value of a select form field on the same page without submitting the form?'

©2018 Martin Webb