Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dreamweaver 04MX Form

Status
Not open for further replies.

04mx

Technical User
Feb 18, 2009
2
AU
How can we validate a checkbox to ensure it must be checked before the form can be submitted.
Can only find ways to validate text fields at present.
Thank you
 
If you want to prevent the form submitting if a check box is not checked you'll need Javascript. You need to check the check box's checked property and act accordingly.

Here's an example:
Code:
<html>
<head><title>Checkbox</title>
<script type="text/javascript">
function  valid_check(){  [green]//Create Function to validate checkbox[/green]
res=document.getElementById('mycheck').checked; [green]//Get value of the checked property of the checkbox[/green]
return res; [green]//Return the value.
}
</script>
</head>
<body>
<form action=check.php method=POST onsubmit="return valid_check();"> [green]//Use the onsubmit event of the form to perform validation and return a value. False stops the form from submitting, true submits the form.[/green]
<input type=checkbox value="9999" name="mycheck" id="mycheck">
<input type="submit" name="send" value="Send">
</form>
</body>
</html>

Since the value of the checked property is false it will prevent the form from being submitted.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top