Javascript Run Function On
Is there a way to execute a javascript function when the user clicks on a certain
Solution 1:
<select>
elements support the onchange
event.
Solution 2:
You HTML would look like this:
<selectonchange="functionName(this.value)"><optionvalue="1"> 1 </option><optionvalue="2"> 2 </option><optionvalue="3"> 3 </option></select>
In your JavaScript, you would have a function ( ex: functionName()
)
and you would use that function to test for each case.
Solution 3:
You can use the change
event to check which option the user clicked on and then execute your desired code.
In Jquery:
$('#yourSelect').change(function(){
var item = $(this).val();
if (item === "Specified Choice")
{
//do your stuff here
}
});
Solution 4:
Here:
elem.onclick = function ( e ) {
if ( e.target.tagName.toLowerCase() === 'option' ) {
// an <option> element was clicked// do your thing
}
};
where elem
is your SELECT element.
Live demo:http://jsfiddle.net/vBB7a/
Solution 5:
You need to hook the onchange
event of the <select>
element, and check the value. Have you tried that?
Post a Comment for "Javascript Run Function On