Forum Moderators: open
<script type="text/javascript">
function isChecked( checkboxId )
{
var cbox = document.getElementById(checkboxId);
if(!cbox ) return false;
if( cbox.checked )
{
return true;
}
return false;
}
</script><form onsubmit="return isChecked(myCheckBox)">
<input type="checkbox" id="myCheckBox" name="myCheckBox">
<input type="submit" name="submit" value="Submit">
</form>
I think that would do it.
Try this...<form onsubmit="return this.checkboxname.checked">
Provided the checkbox is located within the html form it should work.
But of course, that will simply confuse the end user as there is no warning given or anything to signify why the form isn't submitting. But separating it out, you could add alert messages or whatever to notify the user to check the box.
Of course server side checking is also necessary if you want to be 100% sure that the box has been checked.
Finally if you use javascript to disable the submit button originally (on page load for example) you can be sure that people with JS disable will still be able to submit the form.
hope this helps