Question:
How do I pass the selected value of a Drop down menu to my function?
Amandine B
2009-01-29 15:04:09 UTC
So I need to hide or display a 2nd drop down based on a selection from a primary drop down. I originally planned to do this with 'onselect=showSecDropDown();' only to find out that onselect doesn't work in dropdowns. So now I have an onchange event handler thrown into the select tag, but how do I pass the value of this element to the relevant function. I've tried document.getElementById, document.getElementByName and a few other things, but I can't get it to work. PLEASE HELP.

I just need to figure out a way to assign the value selected in the drop down to a variable in the function.

Example:
function showSecDropDown(){
var sel = VALUE OF FIRST DROP DOWN;
if (sel=="Option 3")
{
rel.style.display = 'block';
}
}

Three answers:
anonymous
2009-01-29 15:13:38 UTC
Put a parameter variable into the function, and pass the selected id as the parameter.
anonymous
2009-01-29 15:13:51 UTC
function showSecDropDown(sel){



if (sel=="3")



...



onchange="showSecDropDown(this.value);

...







On change, your function will be passed the value.
kellyann
2016-10-30 07:17:00 UTC
certainly I certainly have seen straight forward yet i think of ican provide help to i take advantage of this in it "" once you press a: rfile.physique.bgcolor = a.identify once you press b: rfile.physique.bgcolor = b.identify once you press c: rfile.physique.bgcolor = c.identify once you press d: rfile.physique.bgcolor = d.identify


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...