Entry
JavaScript: List: Option: Text: How to get the text of a chosen option in <SELECT><OPTION> list?
Oct 16th, 2004 16:11
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 08 September 2004 - 03:51 am ------------------
JavaScript: List: Option: Text: How to get the text of a chosen option
in <SELECT><OPTION> list?
---
Use the 'text' property
---
--- cut here: begin --------------------------------------------------
<HTML>
<BODY>
<FORM
NAME = "form1"
>
<SELECT
NAME = "list1"
ONCHANGE = ' alert( document.forms.form1.list1.options[
document.forms.form1.list1.selectedIndex ].text );'
>
<OPTION>Your option 1</OPTION>
<OPTION>Your option 2</OPTION>
</SELECT>
</FORM>
</BODY>
</HTML>
--- cut here: end ----------------------------------------------------
---
---
Note:
the 'value' property does not give a result here
(it returns an empty string)
e.g.
alert( document.forms.form1.list1.options[
document.forms.form1.list1.selectedIndex ].value );
----------------------------------------------------------------------