Call a function based on the onchange-event
StackOverflow Question:My Answer
I have been used addEventListener in change state so that it will easy to call two different functions by select tag HTML. Check the link given below.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1 id="eg"></h1>
<select id = "nextGeneration" >
<option value="1">1</option>
<option value="2">2</option>
</select>
<script type="text/javascript">
document.getElementById("nextGeneration").addEventListener("change", function(){
if(document.getElementById("nextGeneration").value == "1")
{
F1();
}
else if (document.getElementById("nextGeneration").value == "2") {
F2();
}
});
function F1(){
console.log(1);
}
function F2(){
console.log(2);
}
</script>
</body>
</html>
Comment it !!! If you have any queries.
I have been used addEventListener in change state so that it will easy to call two different functions by select tag HTML. Check the link given below.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1 id="eg"></h1>
<select id = "nextGeneration" >
<option value="1">1</option>
<option value="2">2</option>
</select>
<script type="text/javascript">
document.getElementById("nextGeneration").addEventListener("change", function(){
if(document.getElementById("nextGeneration").value == "1")
{
F1();
}
else if (document.getElementById("nextGeneration").value == "2") {
F2();
}
});
function F1(){
console.log(1);
}
function F2(){
console.log(2);
}
</script>
</body>
</html>
Comment it !!! If you have any queries.
Comments
Post a Comment