Forum Moderators: open

Message Too Old, No Replies

Access Value between two <option> tags

         

Sonnenblume

12:57 pm on Jan 27, 2007 (gmt 0)

10+ Year Member



Say I have the following html...

<form name=example>

<select name=test onChange='Choice();'>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

</form>

How would I access the value between the 2 option tags for the purposes of copying it into a text field?

I know how to do it if I wanted the actual value (i.e. 1, 2 or 3), but how would I access the actual text (one, two, three).

I know for the former I would use something like "myTextField.test.value = example.test.value;" but how would I do the latter.

mrhoo

2:38 am on Jan 28, 2007 (gmt 0)

10+ Year Member



<form name="example">

<select name="testing" onChange='Choice();'>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

</form>

var s=document.example.testing;
var txt=s.options[s.selectedIndex].text
or
var s=document.getElementsByName('testing')[0];
var txt=s.options[s.selectedIndex].firstChild.nodeValue