I have a web form on this page that's using jQuery based form field validation:
https://www.evergladesholidaypark.com/ehp-landingpage-markup/
Here's a link to the JS file that contains the validation script(s):
https://www.evergladesholidaypark.com/ehp-landingpage-markup/js/jquery.main.js
On the form .. I have the following DIV which is currently hidden by default:
<div class="error-message">
You have either left one or more of the required fields in the form blank, or filled them out incorrectly. Please apply the necessary corrections before re-submitting then form.
</div>
Right now .. if you just click on the submit button without filling in any of the fields, .. the .error-message DIV is displayed for about 3 seconds, and then fades out. I'm doing that using this code snippet which starts at about line number 305 in the JS file:
if (success != true) {
$(".error-message").show().delay(3000).fadeOut( "slow");
}
The problem, however, is that I've placed this code inside the "checkSuccess" handler --- which is also being fired whenever an "onChange" event is triggered by any of the form fields. This is obviously resulting in undesired effect .. where the error message repeatedly gets displayed adn then fades out, ... making the page grow and then shrink repeatedly.
What I'd like to do is change the script so that the .error-message DIV is only displayed when the following rules are met:
1) The submit button has been clicked.
2) One or more of the required fields in the form has failed the validation
In other words, .. I'd like to disassociate the showing of the .error-message DIV from the onChange events that are triggered by interacting with the form fields.
How would I do that? And how can I also force the immediate hiding of that .error-message DIV when the submit button is clicked and all of the validation rules have been met (in addition to actually submitting the form)?
Thanks,
- Yvan
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.