Open Bug 332561 Opened 19 years ago Updated 2 years ago

Multiple problems with using onkeydown to restrict input

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

1.8 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: joe, Unassigned)

Details

(Keywords: platform-parity, testcase)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060124 Firefox/1.5.0.1 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060124 Firefox/1.5.0.1 Where code uses javascript onKey events to control what data can be entered in fields firefox seems to behave differently on different platforms. As an example take this code for an input which should stop the user from pressing the '0' key: <input onKeyDown=' if((event.keyCode == 48)) { return false; } return true; ' /> This works perfectly in windows (Firefox 1.5.1 and IE), in linux firefox 1.5.1 it works but can be bypassed by holding the 0 key down, and on Mac OSX firefox it never restricts keypresses. Obviously this is a trivial example, but demonstates the inconistancy which is a real pain when your using firefox as a webapp platform! Reproducible: Always Steps to Reproduce: 1. Use the paste the code in the bug details into a html file 2. Load that file in firefox on multiple platforms. 3. Try entering the restricted '0' key which should not be enterable as any keydown with that keycode should return false.
You can work around both of these problems by using onkeypress (with event.charCode) instead of onkeydown (with event.keyCode). The fact that you're able to use onkeydown to restrict input at all is a relatively new hack (see bug 167145).
Assignee: nobody → events
Component: General → Event Handling
Product: Firefox → Core
QA Contact: general → ian
Summary: Onkey events behave inconistantly. → Multiple problems with using onkeypress to restrict input
Version: unspecified → 1.8 Branch
I think you need to file separate bug reports for each issue (the Mac issue and the Linux issue). Chances are they need different fixes, possibly from different people. Once you've filed both bugs, please mention the bug numbers here and close this bug as invalid. Btw, the Linux issue might be cross-platform but just not show up on Windows due to bug 91592.
Keywords: pp, testcase
Summary: Multiple problems with using onkeypress to restrict input → Multiple problems with using onkeydown to restrict input
The Mac issue has been filed as bug 333475.
Assignee: events → nobody
QA Contact: ian → events
Component: Event Handling → User events and focus handling
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.