html - Javascript: display an alert when a form is checked? -
i have created simple web app has 2 form selections, when user makes selection each want alert
display showing them choices made.
i have attempted below when both forms checked alert not displayed. missing? note see comment:
//below not being displayed should
current code:
<!doctype html> <html> <body> <h1>calculator</h1> <p>select importance of this:</p> <form method="get"> <input type="checkbox" name="severity" value="negligible"> negligible<br> <input type="checkbox" name="severity" value="minor"> minor<br> </form> <p>select probability of this:</p> <form method="get"> <input type="checkbox" name="probability" value="improbable"> improbable<br> <input type="checkbox" name="probability" value="remote"> remote<br> <input type="checkbox" name="probability" value="occasional"> occasional<br> <button onclick= "analysethis()"> analyse </button> <br> <script> function analysethis(){ var severities = document.getelementsbyname('severity'); var probs = document.getelementsbyname('probability'); var severity = undefined; for(var = 0; < ages.length; i++) { if(severities[i].checked) { age = severities[i].value; } } var probability = undefined; for(var = 0; < probs.length; i++) { if(probs[i].checked) { probability = probs[i].value; } } //below not being displayed should alert("severity is: " + age + "probability is: " + probability); } </script> </body> </html>
i use jquery , use click function of button submit.
here example:
$(document).ready(function () { $("{form id/class button id/class or button id/class}").click(function(e) { e.preventdefault(); //perform validation //if good... $("{form id/class}").submit(); }); });
Comments
Post a Comment