mykola
mykola

Reputation: 1808

Is it possible to change symbol before it's printed with javascript?

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?

Upvotes: 2

Views: 154

Answers (3)

Gourav khanna
Gourav khanna

Reputation: 1391

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.

Upvotes: 0

Dave G
Dave G

Reputation: 9767

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/

Upvotes: 0

Jan Pfeifer
Jan Pfeifer

Reputation: 2861

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

Upvotes: 3

Related Questions