document.getElementById("cform").addEventListener("submit", function(event) { event.preventDefault(); // Prevent default form submission grecaptcha.ready(function() { grecaptcha.execute('6LdyGrEUAAAAAAXD3J_rsgZi_r7vls3xfYlYix9e', { action: 'submit' }).then(function(token) { // Append token to the form document.getElementById("g-recaptcha-response").value = token; document.getElementById("cform").submit(); // Submit the form after getting the token }); }); }); document.getElementById("cform").addEventListener("submit", function(event) { let answer = document.getElementById("math").value; if (parseInt(answer) !== 7) { event.preventDefault(); // Prevent submission alert("Incorrect answer to the math problem. Please try again."); return false; } });