Skip to main content

Posts

Showing posts from April, 2016

JavaScript: How to Cancel Form Submit If the Input Value Is Blank

Hello there, let's start. 🙂 We will see examples on how to cancel form submission using: HTML5 required attribute. Combined with additional JavaScript technique. There is a demo page here on Monkey Raptor as landing page for the form submission — so that we could validate both techniques. The page will show us the query string through GET request method. For the Glory of Clarity The title of the post is rather ambiguous, because “but first, let's honour the holy required tag…” 🤣⁉️🙋‍♂️ 💡 This post is more about augmenting default HTML5 behaviour with a bit of JavaScript preventDefault() and manual .submit() after doing checks. ✅ And thus, the vagueness vanishes. Humbly collected the thrown bricks, at your service. HTML5 required attribute Demonstration SUBMIT Code SUBMIT The form above will not be submitted if the input value is empty. But sometimes, user can type in ...
Monkey Raptor uses cookies or biscuits 🍪 for analytics, functionality, and advertisements. More info in Privacy Policy