let currentCaptcha = "";
function generateCaptcha() {
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
let code = "";
for (let i = 0; i < 6; i++) {
code += chars.charAt(Math.floor(Math.random() * chars.length));
}
currentCaptcha = code;
document.getElementById("captcha-box").innerText = code;
}
function validateForm(event) {
const userInput = document.getElementById("captcha-input").value;
if (userInput !== currentCaptcha) {
alert("Invalid CAPTCHA! Please try again.");
generateCaptcha(); // Refresh it so they have to try a new one
event.preventDefault(); // Stop the form from submitting
return false;
}
alert("Success! Form submitted.");
return true;
}
// Initialize the captcha when the page loads
window.onload = generateCaptcha;