× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Pressing 'Enter' executes Cancel button instead of Submit

Utkarsh Upadhyay
Apr 16, 2015
<p>The default <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button" rel="nofollow"><code>type</code> for buttons is <code>submit</code></a>. You have to explicitly <em>unset</em> it to <code>"button"</code> to avoid the submit action:</p> <pre class="lang-html prettyprint-override"><code>&lt;p class="stdformbutton"&gt; &lt;button class="btn btn-default" type="button" ui-sref="app.project.list"&gt;Cancel&lt;/button&gt; &lt;button class="btn btn-primary" type="submit"&gt;{{saveMessage}}&lt;/button&gt; &lt;/p&gt; </code></pre> <p>You can also set the <code>type="reset"</code> if you want it to clear out the <code>input</code> values.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/24011853/Pressing%20'Enter'%20executes%20Cancel%20button%20instead%20of%20Submit/24012250">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus