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 Leonidas. Obviously I'm going to need to consolidate my 2 different JS files somehow.
- Yvan
JavaScript
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.