The form's onsubmit function triggers a pop-up message asking the user if they want to proceed before submitting the form. This requires the onsubmit function to wait for the user's final input in order to fully execute the form.
Here is the code snippet:
<form name="mailF" id="mailF" method="post" onsubmit="event.preventDefault(); return get_answer(null)" action="Mail-sender.php" enctype="multipart/form-data">
//more form data...
</form>
<div id="question">
Are you sure you want to send this email?
<button onclick="get_answer('Send')">Yes</button>
<button onclick="get_answer('No')">No</button>
</div>
Javascript:
function get_answer(val){
document.getElementById("question").style.display = "block";
if(val === "Send"){
return true;
}else if(val === "No"){
return false;
}else{
get_answer(val);
}
}
I attempted to resolve this issue by continuously looping the get_answer function until the value is either "Send" or "No." However, I encountered an error in the console stating: Uncaught RangeError: Maximum call stack size exceeded. Is there a better way to implement this without encountering this error?
NOTE: I included event.preventDefault(); in the form to prevent it from executing the action after throwing an error.
Thank you