Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI I have two textboxes one for dollars and another for cents.....i want javascript validation..dollar textbox shoud accept only numbers and dot operator...if i press "." from my keyboard it should jump to next box(cents) which also accepts only numbers..However I tried considering charcode of "." operator i.e."190"...but its working from keyboard but not number pad..My CLIENT wants it from number pad '.' press.....please help
Posted

Use key code 110 with OR condition which is for decimal point.

list of key codes

http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes[^]
 
Share this answer
 
You can use onkeydown or onkeypress event to trap the event keycode and then press tab keycode.

Try something like this for the textbox:
HTML
<input type="text" onkeydown="EnterToTab()">

JS code:
JavaScript
function EnterToTab(){
  if (event.keyCode==110)
    event.keyCode=9;
  }

Pick the appropriate keycode from here: Javascript Char Codes (Key Codes)[^] - Looks like it's 110 for your case.

PS: This is not suggestible as Enter and Tab have two different functions to perform and playing with them like this not good.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900