The after-form-submit is the set of code that is executed after a submit button is fired. Usually, it is used to blank out the form, once the submit is given. For Example, When the login credentials are wrong, the input becomes blank in the form.
- First, the elements in a form must be ensured if it is loaded.
- Then, the submit method is added a callback function.
- Once the submit button is clicked, it should prevent successive callbacks.
- Followed by that, a timeout is given because of a need for delay. If there is no delay, the actions that should happen after would happen at the beginning itself. Like before validating the password, the input form shouldn’t blank out.
- Then the actions that need to be performed are given at the end.
- A callback to the jQuery method can be done using the submit button.
- Once the submit button of the form is clicked, the callback function is fired. But, before that, the DOM (document object manipulation) must be loaded. Once the DOM is loaded, it then calls any of these methods. ( window.on(‘load’) or document.ready() or window.ready() can be used).
- The preventDefault() method prevents the method from firing multiple times.
- We use setTimeout method to perform after submit with few milliseconds.
Note: The window.ready() method is called when all the resources are loaded and document.ready() method is called when DOM is loaded.
This form submit method triggers the callback method, which at first prevents further callbacks. Then after a time interval of 100 milliseconds, the alert method is called with the text input value.
- How to specify the response page after submitting the form using HTML5 ?
- jQuery | Callback Functions
- How to perform click-and-hold operation inside an element using jQuery ?
- How to access the correct `this` inside a callback?
- Implementing callback in PHP
- Node.js | Callback Concept
- How to convert an existing callback to a promise in Node.js ?
- What is callback hell in Node.js ?
- How to operate callback based fs.appendFile() method with promises in Node.js ?
- How to operate callback-based fs.lstat() method with promises in Node.js ?
- How to operate callback-based fs.opendir() method with promises in Node.js ?
- How to operate callback-based fs.rename() method with promises in Node.js ?
- How to operate callback-based fs.truncate() method with promises in Node.js ?
- How to operate callback-based fs.readFile() method with promises in Node.js ?
- How to operate callback-based fs.readdir() method with promises in Node.js ?
- How to operate callback-based fs.mkdir() method with promises in Node.js ?
- How to operate callback based fs.writeFile() method with promises in Node.js ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.