Last Updated: May 31, 2021
·
9.037K
· 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>

1 Response
Add your 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 ·