I'm new to asking questions here, but I've been reading articles and questions for a while now. My question is about a specific part of a code that has been causing me trouble.
In my project, I have a registration form with both JS validation and server-side validation. I wanted to disable form submission until the JS validation passed, and I set certain conditions for that. However, I encountered a problem when those conditions were met. I tried using the following line to prevent form submission:
$('.memberReg').on('submit', function(){return false;});
For instance, in a situation like this:
if(response.okText == 'SUCCESS' && response.warning == null )
{
$('label[for="email"]').addClass("success");
$('label[for="email"]').append("<span> is not yet registered!</span>");
console.log(result);
}else
{
$('label[for="email"]').addClass("error");
$('label[for="email"]').append("<span> is already taken!</span>");
$('.memberReg').on('submit', function(){return false;});
}
The issue here is that the form is blocked from submitting entirely, even when other conditions are met. In this example, even with the correct email, the form cannot be submitted anymore.
I attempted to use a variable with true-false statements for a validForm() function to submit the form, but the function kept looping and the form remained disabled.
I also tried using `return true` for form submission in the valid email part, but it had the same effect.
Does anyone know how to block form submission only under certain conditions without completely disabling it, so that the user would need to refresh the page to send the form?