JSFiddle - React, Tailwind, and code Playground
HTML
<h1>Checkbox Must Be Checked for Form Submit</h1>
<p>This script requires that a checkbox is checked before allowing a form to be submitted.
<p> </p>
<form action="../" onsubmit="return CheckboxValidator(this);">
<p><input type="checkbox" name="toscheckbox" value="I agree to the Terms of Service."> <label>I agree to the <a href="http://companypolicies.org/terms-of-service" target="_blank">Terms of Service</a> and will do whatever you ask in the future forever and ever and so will my kids and...</label>
<div id="myDiv"></div>
<br /><input type="submit" value="Submit!"></p>
</form>
<div id="myDiv"></div>
CSS
h1 {font-size:25px; font-family:arial, sans, verdana}
p {font-size:13px; font-family:arial,sans,verdana}
label {font-size:10px; font-family:arial, sans, verdana; font-style:italic}
myDiv {color:#ff0000; font-size:16px; background:#00FFFF}
JavaScript
<!--
function CheckboxValidator(theForm) {
if (
theForm.toscheckbox.checked == false)
{
var txt=document.getElementById("myDiv")
txt.innerHTML="<b style=\"color:#f00; font-size:18px; background:#ff0\">↑ You MUST check the box that agrees to our Terms of Service! </b>";
return false;
} else {
document.open;
document.write('OK. We are satisfied. Good boy.');
document.close;
return false;
}
}
//-->