PDA

View Full Version : Form validating


florida
05-13-2003, 09:00 PM
Please advise how I can make sure a check box is checked?

I have check boxes on my form and want to do a data validation to make sure a box is checked. So the form will not go out until one of the boxes has a check in it.

Thanks

A1ien51
05-13-2003, 09:06 PM
Basic Idea


if(document.FormName.CheckBoxName.checked){
retrun true; //Checked
}
else{
return false; //
}

cheesebagpipe
05-14-2003, 06:45 AM
<html>
<head>
<title></title>
<script type="text/javascript" language="JavaScript">

function checkabox(oForm) {
var el, i = 0;
while (el = oForm.elements[i++])
if (el.type == 'checkbox' && el.checked)
return true;
alert('I beg you, check-a-box. For God\\'s sake, check-a-box.');
return false;
}

</script>
</head>
<body>
<form action="javascript:alert('OK.')" onsubmit="return checkabox(this)">
<input type="checkbox"> a<br />
<input type="checkbox"> b<br />
<input type="checkbox"> c<br />
<input type="checkbox"> d<br />
<input type="checkbox"> e<br /><br />
<input type="submit">
</form>
</body>
</html>