ThunderLee Posted February 25, 2010 Share Posted February 25, 2010 Hi everyone, I'm not sure if this is in the correct section but its frustrating me because I can't seem to find a answer.. What I'm trying to do is... I want a text input box with a $ sign and a . in the box, when a user types 1000 it would show $10.00 in the box, same with date, I type 01012000 would show 01/01/2000.. I have seen this on a website somewhere but I tried looking at the source and I can't figure out how they did it.. I would like someone to try to help me find a solution because its frustrating me .. Quote Link to comment Share on other sites More sharing options...
straylight Posted February 25, 2010 Share Posted February 25, 2010 This kind of thing requires a little bit of thought, here's a summary of what needs to be implemented: 1) Add an event handler function for the "keyup", "keydown" or "keypress" events of the text box. 2) In the event handler function, extract the string in the text box and process it so that it gets converted (for example, changing 1000 to $10.00. 3) At the end of the function, set your freshly processed string (e.g. "$10.00") back into the text box The hardest bit here will be getting it to work in different browsers - those key related events aren't very well implemented in IE. I've done something similar before, and used a javascript framework (prototype) for it. Doing that can save you a lot of hassle because using framework methods gives consistent results in different browsers. Good luck Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.