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 functionalert("an01");
}
elseif(this.value == "AN02")
{
//do this functionalert("an02");
}
elseif(this.value == "AN03")
{
alert("an03");
}
};
You could add a function that gets called everytime you change the value :
HTML
<selectname = "navyOp"onChange="myFunction()"><optionselected = "selected">Select a Navy Op Area</option><optionvalue = "AN01">AN01</option><optionvalue = "AN02">AN02</option><optionvalue = "AN03">AN03</option></select>
JS
var myDropdown=document.getElementsByName('navyOp')[0];
functionmyFunction(){
alert('option changed : '+myDropdown.value);
}
One way to do this is
functionexpand(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"