Analyse this code and temme why it is used so

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haridhasekar
    New Member
    • Feb 2010
    • 8

    Analyse this code and temme why it is used so

    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.....

    Code:
    function isnumeric(e,obj)
    {
    	var keynum;
    	if(window.event) 	
                    {
    	keynum=e.keyCode;
    	}
    	else if(e.which) 	
                    {
    	keynum=e.which;
    	}
    	
    	return((keynum >= 48 && keynum <= 57) ||keynum==189|| keynum==46 ||(keynum>=32 && keynum<=40) || keynum == 8 || keynum==9 ||(keynum >=96 && keynum <=105));
    }
    Last edited by Dormilich; Feb 27 '10, 11:37 PM. Reason: Please use [code] tags when posting code
  • larztheloser
    New Member
    • Jan 2010
    • 86

    #2
    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...

    Comment

    • haridhasekar
      New Member
      • Feb 2010
      • 8

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

      Comment

      • larztheloser
        New Member
        • Jan 2010
        • 86

        #4
        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.

        Comment

        • haridhasekar
          New Member
          • Feb 2010
          • 8

          #5
          Thanks frnd... i got it clearly.... thanks for ur reply....

          Comment

          Working...