Source Code:
(back to article)
Submit
Result:
Report an issue
<div> <pre> <form id="conditionalForm"> Accept Terms: <input type="checkbox" id="acceptTerms"> <button type="button" onclick="checkAndSubmit()">Submit</button> </form> <script> function checkAndSubmit() { var form = document.getElementById('conditionalForm'); var termsCheckbox = document.getElementById('acceptTerms'); if (termsCheckbox.checked) { form.submit(); } else { alert('You must accept the terms and conditions to proceed.'); } } </script> </pre> </div>