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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.