2

Does anybody know how to change an entered symbol seamlessly with javascript? Because when I just replace an already-printed symbol with the desired one (something like onkeyup="this.value=this.value.replace(/,/g,'.')"), the user sees the replacement occur: you press comma, comma is printed, then it's replaced by a dot. Of course, it happens quickly so it's not a big problem, but anyway I want the dot to be printed immediately without printing and replacing the comma first. Is it possible?

McGarnagle
  • 98,751
  • 30
  • 222
  • 258
mykola
  • 1,626
  • 5
  • 25
  • 35

3 Answers3

3

You will have to cancel default event and add the other character to the input manually

Look at this question it should help you: how to insert dot instead of comma in js keypress

Community
  • 1
  • 1
Jan Pfeifer
  • 2,316
  • 24
  • 32
0

Try using onkeydown instead and stop the event from propagating.

A quick fiddle I did to try this out ... this is quick and dirty and may cause issues.

http://jsfiddle.net/djgraff209/KpR52/3/

Dave G
  • 9,441
  • 34
  • 40
  • Use the technique referenced by Jan Pfeifer. It is much more robust than the q&d I did above. – Dave G Oct 07 '11 at 13:01
0

Yes , You have to use javascript event like
1) onkeydown
2) onkeyup
to achieve your task. So first try yourself .
If you have further problem then you can ask..But First TRY yourself.

Gourav khanna
  • 1,311
  • 1
  • 11
  • 15