Drop Down Menu With Onclick Javascript Functions
I'm trying to create a drop down menu that calls a JavaScript function when clicked. My drop down menu is like this:
You can try this
html change or edit:
<select name = "navyOp" id = "navyOp">
JavaScript:
document.getElementById("navyOp").onchange = function()
{
if(this.value === "AN01")
{
//do this function
alert("an01");
}
else if(this.value == "AN02")
{
//do this function
alert("an02");
}
else if(this.value == "AN03")
{
alert("an03");
}
};
You could add a function that gets called everytime you change the value :
HTML
<select name = "navyOp" onChange="myFunction()">
<option selected = "selected">Select a Navy Op Area</option>
<option value = "AN01">AN01</option>
<option value = "AN02">AN02</option>
<option value = "AN03">AN03</option>
</select>
JS
var myDropdown=document.getElementsByName('navyOp')[0];
function myFunction(){
alert('option changed : '+myDropdown.value);
}
One way to do this is
function expand(s)
{
var td = s;
var d = td.getElementsByTagName("div").item(0);
td.className = "menuHover";
d.className = "menuHover";
}
You have to do this for each of your options menu. Hope this answers your question
Post a Comment for "Drop Down Menu With Onclick Javascript Functions"