Write a simple JavaScript program in which the user selects
Write a simple JavaScript program in which the user selects choices from some of the following: checkboxes, radiobuttons, pushbuttons, selections lists, and then the user clicks a submit button, which then prints the choices that the use selected. Very simple JavaScript.
Solution
<!DOCTYPE html>
<html>
<body>
<form onsubmit=validate()>
<input type=\"radio\" name=\"gender\" value=\"male\" checked> Male<br>
<input type=\"radio\" name=\"gender\" value=\"female\"> Female<br>
<input type=\"radio\" name=\"gender\" value=\"other\"> Other
<input type=\"submit\" value=\"Submit\">
</form>
</body>
</html>
Javascript -
function validate()
{
var val=document.getElementByName(\"gender\");
alert(\"you selected\"+val);
}
