question about select in forms

K

Ken1

Hello, lets say i have a select like this:
<select name="numbers" id="numbers">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

Lets say a user selects "Two" from the drop down menu... now I want to
get that "Two" into a variable... but not "2" because i can get 2 by
using numbers.value..... but how could i get the "Two" into a variable?
 
A

ASM

Ken1 a écrit :
Hello, lets say i have a select like this:
<select name="numbers" id="numbers">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

Lets say a user selects "Two" from the drop down menu... now I want to
get that "Two" into a variable... but not "2" because i can get 2 by
using numbers.value..... but how could i get the "Two" into a variable?

var o = document.forms['myForm'].elements['numbers'].options
myVariable = o[o.selectedIndex].text;

o = document.myForm.numbers.options;
o = document.forms[0].numbers.options;

<select name="numbers" id="numbers"
onchange="var k = this.selectedIndex;
myVariable = this.options[k].text;
">
 
K

Ken1

thanks! ill try this out.
Ken1 a écrit :
Hello, lets say i have a select like this:
<select name="numbers" id="numbers">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

Lets say a user selects "Two" from the drop down menu... now I want to
get that "Two" into a variable... but not "2" because i can get 2 by
using numbers.value..... but how could i get the "Two" into a variable?

var o = document.forms['myForm'].elements['numbers'].options
myVariable = o[o.selectedIndex].text;

o = document.myForm.numbers.options;
o = document.forms[0].numbers.options;

<select name="numbers" id="numbers"
onchange="var k = this.selectedIndex;
myVariable = this.options[k].text;
">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top