Ladies and Gentlemen, hello. This is my first post here ever.
The following two simple examples are to perform the same task - block numeric input in text field, except one of the works in Opera and the other one doesn't:
Example from W3 Schools - DOES NOT WORK!
Example from MR ED KJ - WORKS!
if(window.event) // IE
keynum = e.keyCode;
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which;
keychar = String.fromCharCode(keynum);
numcheck = /\d/;
<input type="text" onkeydown="return noNumbers(event)" />
The scripts were tested under Windows XP Pro SP3 using the following browsers:
var key = window.event ? e.keyCode : e.which;
var keychar = String.fromCharCode(key);
reg = /\d/;
<input type="text" onkeypress="return onKeyPressBlockNumbers(event);" />
- Chrome: 18.104.22.168
- IE: 8.0.6001. 18702IC
- Firefox: 3.0.13
- Flock: 2.0.3
- Opera: 9.63
- Safari 3.2.1 (525.27.1)
Any ideas what the reason may be? There's good chance this problem will be popping up frequently in the future, so it would really help to know what makes those things tick.
Thank you for your time.