Open Bug 322490 Opened 15 years ago Updated 2 years ago
You have to use event.preventDefault(); when you use addEventListener, you can't cancel the event with return false in that case.
Ok. But why does any of the mentioned changes (second input / alert box / element.onkeypress) give me the - if I understand you right - wrong behavior?
Interesting. There is indeed a difference there when another form control is in the form. Adding an alert doesn't make a difference to me. I've removed the return false in this testcase completely, since it doesn't seem to matter in the difference of behavior.
Assignee: nobody → events
Component: General → Event Handling
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → Trunk
Ah, see: http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/content/html/content/src/nsHTMLInputElement.cpp&rev=1.419#954 That is actually wanted behavior. When there are more than two text controls in a form without a submit button, the form will not submit when pressing enter, that is also what IE6 does.
So that's why adding a second input tag 'works', form submission by pressing enter is then automatically suppressed.
I cancel the event now to prevent automatic form submission. But I have to say that this is not a very self-explanatory behavior. What was the background of IE to handle only-one-input-forms special? Arbitrariness? Where is it used or is this a compatibility thing that should be dropped? Thanks for the clarification.
Component: Event Handling → User events and focus handling
You need to log in before you can comment on or make changes to this bug.