Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  135] [ 6]  / answers: 1 / hits: 131787  / 14 Years ago, sun, january 9, 2011, 12:00:00

I am trying to build a form that fills in a person's order.


<form name="food_select">
<select name="maincourse" onchange="firstStep(this)">
<option>- select -</option>
<option text="breakfast">breakfast</option>
<option text="lunch">lunch</option>
<option text="dinner">dinner</option>
</select>
</form>

What I'm trying to do is send in the select object, pull the name and the text/value from the option menu AND the data in the option tag.


function firstStep(element) {
//Grab information from input element object
/and place them in local variables
var select_name = element.name;
var option_value = element.value;
}

I can get the name and the option value, but I can't seem to get the text="" or the value="" from the select object. I only need the text/value from the option menu the user selected. I know I can place them in an array, but that doesn't help


var option_user_selection = element.options[ whatever they select ].text 

I also need to use the passed in select reference as that is how it's set up in the rest of my code.


Later on, that text/value is going to be used to pull the XML document that will populate the next select form dynamically.


More From » html

 Answers
21

You can use:



var option_user_selection = element.options[ element.selectedIndex ].text

[#94306] Friday, January 7, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frederickmohamedw

Total Points: 21
Total Questions: 123
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
frederickmohamedw questions
Wed, Sep 23, 20, 00:00, 4 Years ago
Sat, Jul 18, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Sat, Jan 11, 20, 00:00, 4 Years ago
Fri, Dec 27, 19, 00:00, 4 Years ago
;