Well, I'm stuck asking you all, because I cannot find a piece of code that works in multiple browsers.
I have the following code that works in google chrome and ie:
[code=javascript]
//Add a keypress watcher to disallow spaces, slashes, alphabetic characters, etc
document.getEle mentById("tbSit eCodeOrSerialNu mber").onkeypre ss=function(){r eturn OnlyNumbers(eve nt);};
[/code]
FF complains that the function is not defined. Looking up I see that FF likes
the function definition to take a parameter in for this setup, aka: function(e)
[code=javascript]
document.getEle mentById("tbSit eCodeOrSerialNu mber").onkeypre ss=function(e){ return OnlyNumbers(eve nt);};
[/code]
But then it complains that "event" is not valid. Ok I think, how about using function (event)
[code=javascript]
document.getEle mentById("tbSit eCodeOrSerialNu mber").onkeypre ss=function(eve nt){return OnlyNumbers(eve nt);};
[/code]
Hurray it works in FF and google chrome, but then IE eats it.
EDIT: No, it blocks EVERY keypress (backspace, ctrl+v, etc) in FF, but googlechrome is fine.
IE complains inside the OnlyNumbers function that a null is being passed in as the parameter.
Does anyone have a solid piece of code for attaching the onkeypress handler at runtime like that?
I have the following code that works in google chrome and ie:
[code=javascript]
//Add a keypress watcher to disallow spaces, slashes, alphabetic characters, etc
document.getEle mentById("tbSit eCodeOrSerialNu mber").onkeypre ss=function(){r eturn OnlyNumbers(eve nt);};
[/code]
FF complains that the function is not defined. Looking up I see that FF likes
the function definition to take a parameter in for this setup, aka: function(e)
[code=javascript]
document.getEle mentById("tbSit eCodeOrSerialNu mber").onkeypre ss=function(e){ return OnlyNumbers(eve nt);};
[/code]
But then it complains that "event" is not valid. Ok I think, how about using function (event)
[code=javascript]
document.getEle mentById("tbSit eCodeOrSerialNu mber").onkeypre ss=function(eve nt){return OnlyNumbers(eve nt);};
[/code]
Hurray it works in FF and google chrome, but then IE eats it.
EDIT: No, it blocks EVERY keypress (backspace, ctrl+v, etc) in FF, but googlechrome is fine.
IE complains inside the OnlyNumbers function that a null is being passed in as the parameter.
Does anyone have a solid piece of code for attaching the onkeypress handler at runtime like that?
Comment