Cancel Button on a form with Required fields
The HTML5 tag parameter required
is very handy except when you want to add a Cancel submit button. To allow the Cancel button to work without the browser giving an error on empty required fields, simply add the formnovalidate
parameter to the Cancel button. Here's an abbreviated form showing the parameter in use:
<form>
<label>Email: <input type="email" name="email" required></label>
<input type="submit" name="submit" value="Submit">
<input type="submit" name="submit" value="Cancel" formnovalidate>
</form>
Written by Sunny Walker
Related protips
1 Response
@kunalvarma05 It may depend on the doctype you're using. The above works for the HTML5 <!DOCTYPE html>
but if you need to, use a full parameter formnovalidate="formnovalidate"
. Also note that, as always, YMMV depending on the browser and version (IE). Here's a fiddle: http://jsfiddle.net/rwzMs/1/
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Html5
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#