javascript cross browser scripting help -


I have a small function that I only allow numerical input. It works great in IE, but I can not get it to work in Firefox or Chrome. I have this JS file which is full of the script tags in my HTML page.

  var numberOnly = function (evt) {var theEvent = evt || Window.event; Var key = theEvent.keyCode || TheEvent.which; Key = string. Lightcode (key); Var REGEX = / [0- 9] = .//; If (! Regex.test (key)) {theEvent.returnValue = false; }}; Var wireElemToEvent = function (elemId, event, joy) {var elem = document.getElementById (elemId); If (typeof window.event! == 'undefined') {elem.attachEvent ("on" + event, func); } And {elem.addEventListener (incident, funny, true); }}; Var wireEvents = function () {wireElemToEvent ("tbxQuantity", "keypress", number only); WireElemToEvent ("Tbxphone", "keypress", number only); WireElemToEvent ("tbxZip", "keypress", number only); }; Window.onload = wireEvents;  

Chrome tells me

file: /// C: /Documents%20and%20Settings/xxx/Desktop/numbersonly/res/js/numbersonly.js: 17 No TypeError: There is no way in # object 'attachEvent'

Any thoughts that I am doing wrong?

Thanks for any help, ~ ck

in wireElemToEvent You can not check that elem after starting it, besides elem.attachEvent and elem.addEventListener Instead of examining existence, it would be better if window.event is defined.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -