By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Analyse this code and temme why it is used so

P: 8
hi all,
pls analyse the code .. temme why it is used so ... is there any alternate method to validate whether it is a numeric....if so temme.....

Expand|Select|Wrap|Line Numbers
  1. function isnumeric(e,obj)
  2. {
  3.     var keynum;
  4.     if(window.event)     
  5.                 {
  6.     keynum=e.keyCode;
  7.     }
  8.     else if(e.which)     
  9.                 {
  10.     keynum=e.which;
  11.     }
  13.     return((keynum >= 48 && keynum <= 57) ||keynum==189|| keynum==46 ||(keynum>=32 && keynum<=40) || keynum == 8 || keynum==9 ||(keynum >=96 && keynum <=105));
  14. }
Feb 27 '10 #1
Share this Question
Share on Google+
4 Replies

P: 86
Well, it is used together with some sort of event handler, such as onkeydown. Different browsers pass different values to event functions so the next few lines have a way of getting the pressed key code for 2 different browsers. Finally the big if checks whether this key code is a number key on the keyboard. So many numbers must be checked cause there are several keyboard configurations.

So far as I know this is the best and most efficient way to do this, and I can't think of another though I bet there is a roundabout way somehow...
Feb 27 '10 #2

P: 8
Can you please explain in detail the words 'Different browsers pass different values to event functions '... whats the need of using keycode....
Feb 27 '10 #3

P: 86
Well, rather than pass a string of the key hit to the function, browsers pass the scancode of the key. This is more suitable for international keyboards. However, some pass it as the event parameter of the first argument of the function, and some as the which parameter (the second argument is not used by the function). I think it is IE that uses e.event.
Feb 27 '10 #4

P: 8
Thanks frnd... i got it clearly.... thanks for ur reply....
Mar 1 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.