It is possible to see if a check box has been checked or not in JavaScript. This may come in handy during form validation. A check box has a checked property, which returns either a 0 for not checked and a 1 for checked. You can also set the property to 0 or 1 to programmatically control the check box.
<html>
<head>
<script language=javascript>
function validate(chk){
if (chk.checked == 1)
alert("Thank You");
else
alert("You didn't check it! Let me check it for you.")
chk.checked = 1;
}
</script>
</head>
<body>
<form>
<input type=checkbox name=chk1>Please Check Me
<p><input type=button value="check" onclick="return validate(chk1);">
</form>
</body>
</html>
Comments
Post a Comment