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

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

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

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

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


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.