How to run JavaScript function when option selected In this example we learn how to run javascript when option selected, we need to do this select and option tag in html, and change event and if condition in Javascript <select id="compress" style="padding:3px 5px"> <option value="select" disabled selected>-- select --</option> <option value="HTML">Compress HTML </option> <option value="CSS">Compress CSS </option> <option value="JS">Compress JavaScript </option> </select> <script> var select=document.getElementById("compress"); select.addEventListener("change", function(){ if(select.value == "HTML"){ alert("HTML") } if(select.value == "CSS"){ alert("CSS") } if(select.value == "JS"){ alert("JS") } }); </script> © Manajmnt code Share to : ☷✎ Comments
Comments
Post a Comment
message