<p>I'm having trouble with events in Internet Explorer 7.</p>

<p>When I have a form with <strong>two or more</strong> <code>input[type=text]</code> and I press enter, the events occurs in this order:</p>

<ol>
<li>submit button (<code>onClick</code>)</li>
<li>form (<code>onSubmit</code>)</li>
</ol>

<p>Sample code:</p>

<pre><code>&lt;form onSubmit="{alert('form::onSubmit'); return false;}"&gt;
    &lt;input type="text"&gt;
    &lt;input type="text"&gt;
    &lt;input type="submit" onClick="{alert('button::onClick');}"&gt;
&lt;/form&gt;
</code></pre>

<p>If I have only <strong>one</strong> <code>input[type=text]</code> and I press enter the submit button <code>onClick</code> event doesn't fire. Sample code:</p>

<pre><code>&lt;form onSubmit="{alert('form::onSubmit'); return false;}"&gt;
    &lt;input type="text"&gt;
    &lt;input type="submit" onClick="{alert('button::onClick');}"&gt;
&lt;/form&gt;
</code></pre>

[{'answer_id': 9327, 'author': 'andrewrk', 'author_id': 432, 'author_profile': 'https://Stackoverflow.com/users/432', 'pm_score': 1, 'selected': False, 'text': '<p>If you want code to run when the user presses enter, <strong>just use the onSubmit handler.</strong></p>\n\n<p>If you want code to run when the user presses the button, and <em>not</em> when the user presses enter, use a button other than type="submit".</p>\n'}, {'answer_id': 9340, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 3, 'selected': False, 'text': "<p>The button's onclick should (I think) only fire if the button is actually clicked (or when the focus is on it and the user clicks enter), unless you've added logic to change that.</p>\n\n<p>Is the addition of the extra textbox possibly changing the tab order of your elements (perhaps making the button the default control in that case)?</p>\n"}, {'answer_id': 22765, 'author': 'bubbassauro', 'author_id': 1328, 'author_profile': 'https://Stackoverflow.com/users/1328', 'pm_score': 1, 'selected': False, 'text': '<p>Interestingly, if you click on the screen (remove the focus from the textbox) on second example with only one textbox, the event onClick fires... So it\'s not an expected behaviour since it only occurs when you have just one textbox <em>and</em> you have the focus on the textbox.<br>\nI\'m afraid you\'ve found a bug on the browser and you\'ll have to find a workaround, or avoid using the onClick event in that case.<br>\nI use the onSubmit event for validations because it\'s a "safer" event that is more likely to work on different browsers and situations.</p>\n'}, {'answer_id': 22768, 'author': 'Brian Warshaw', 'author_id': 1344, 'author_profile': 'https://Stackoverflow.com/users/1344', 'pm_score': 1, 'selected': False, 'text': "<p>Out of curiosity, are you using a DOCTYPE, and if so, which one? I'm not saying incompatabilities with the DOCTYPE are the issue, but quirks mode is something to rule out before trying anything else.</p>\n"}, {'answer_id': 3196171, 'author': 'mplungjan', 'author_id': 295783, 'author_profile': 'https://Stackoverflow.com/users/295783', 'pm_score': 2, 'selected': False, 'text': '<p>From the dawn of browsers, a single input field in a form would submit on enter with or without a submit button. This was to make it simpler for people to search a site from a single search field.</p>\n\n<p>If you need to execute some javascript in a form, it is safer practice to use the onsubmit of the form (and return false to stop submission) rather than executing script in the onClick of the submit button. If you need to execute javascript from a button, use type="button" instead of type="submit" - hope this clarified what I meant</p>\n'}, {'answer_id': 35775438, 'author': 'Crystal Paladin', 'author_id': 5917094, 'author_profile': 'https://Stackoverflow.com/users/5917094', 'pm_score': 0, 'selected': False, 'text': '<p>You might want to include a dummy hidden input element to recreate the situation where you had two input elements... that way, you\'ll get both of the events fired</p>\n\n<pre><code>&lt;FORM onSubmit="{alert(\'form::onSubmit\'); return false;}"&gt;\n    &lt;INPUT TYPE="text"&gt;\n    &lt;input type="hidden" name="dummy"&gt;\n    &lt;INPUT TYPE="submit" onClick="{alert(\'buttom::onClick\');}"&gt;\n&lt;/FORM&gt;\n</code></pre>\n\n<p>IE has a lot of confusing fixes that needs to be done for improving compatibility of our code</p>\n'}]
['https://Stackoverflow.com/questions/9301', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1100/']