Jump to content

How to add period/dollar sign in input.. read for details :S


ThunderLee

Recommended Posts

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 :D..

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.