itb2hq
Last Updated: February 25, 2016
·
2.753K
· thunderpaw

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>
Say Thanks
Respond

2 Responses
Add your response

3149
Pro pic

Doesn't work :(

over 1 year ago ·
3239

@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 ·