javascript for textbox that accept only numbers
-
hi i have writen javascript to accept only numbers for a textbox function validate() { var e = window.event.keyCode; if(!((e>=96 && e<=105)||(e>=48 && e<=57))) return false; } i m calling this function on keyup event of textbox but problem is that after returning false it write the char in textbox. how can i do that.... Thanks
Dinesh Sharma
-
hi i have writen javascript to accept only numbers for a textbox function validate() { var e = window.event.keyCode; if(!((e>=96 && e<=105)||(e>=48 && e<=57))) return false; } i m calling this function on keyup event of textbox but problem is that after returning false it write the char in textbox. how can i do that.... Thanks
Dinesh Sharma
DineshSharmain wrote:
keyup event
Try keydown / keypress instead - keydown will prob stop it if you return false...
"Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)
-
DineshSharmain wrote:
keyup event
Try keydown / keypress instead - keydown will prob stop it if you return false...
"Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)
Thanks for your interest... i have tried all the events but still it display the char. that i don't want. please suggest me if any other way to accept only numeric. these textboxes are generating at run time. :confused:
Dinesh Sharma
-
Thanks for your interest... i have tried all the events but still it display the char. that i don't want. please suggest me if any other way to accept only numeric. these textboxes are generating at run time. :confused:
Dinesh Sharma
It's all about the code that you use for the key press. It also matters if you're using FF or IE. I suggest googling, there are tons of examples on the web on how to do this.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
hi i have writen javascript to accept only numbers for a textbox function validate() { var e = window.event.keyCode; if(!((e>=96 && e<=105)||(e>=48 && e<=57))) return false; } i m calling this function on keyup event of textbox but problem is that after returning false it write the char in textbox. how can i do that.... Thanks
Dinesh Sharma