I'm working on getting an old piece of code working, from 2003. I'm trying to replicate an ATM style decimal textbox. This code claims to have worked for someone, but I am having trouble implementing it.
Maybe someone has a better way of achieving this? Maybe in jQuery?
Well, the code for processing the input can easily be made like this:
It might be a challenge getting it back into the textbox without getting conflicts, but you could 'fake' it by doing something like this:
http://jsfiddle.net/AnfCn/1/
Disclaimer: Quick and dirty
This is how I would solve it: http://jsfiddle.net/77bMx/86/
The basic idea is to intercept any input to the box, make sure it's of the correct type (a number, or a backspace) and then add it to a backing storage string (
var input
), and then format that string to display correctly. The user never directly enters anything into the text box, since I usereturn false
at the end of the event handler.