Advanced Search

Results 1 to 3 of 3

Thread: Convert String abbreviation value to numbers

  1. #1
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question Convert String abbreviation value to numbers

    Hello,

    Does anyone know if there is a script that converts a string value to a number?

    Heres what I'm trying to do;
    If you have a form text field that warrants a dollar value to be entered like "6,000,000,000, 6,000,000 or 6,000". I would like to make it available for the user to enter an abreviation of "6b, 6m or 6th" in the form field and once it's entered, it changes the letter abreviation (b, m or th) to the full numeric value (,000,000,000 or ,000,000 or ,000).

    ex: 6b=6,000,000,000 / 6m=6,000,000 / 6th=6,000

    Can anyone help with this?
    Thanks!

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hi Bigalo,

    First of all, I'm not a big javascript guy so this won't be the complete answer, but it should get you started.

    I can easily do what you want in PHP with the str_replace function -- bascially swap out each instance of a set string with another.

    Now, there is a similar method in JavaScript -- the replace() method

    Code:
    stringObject.replace(findstring,newstring)
    Now, you could use that for your string replacement. Then you would use the DOM to write the results of this method back into your textbox/area.

    I also imagine you'll need some sort of triggering this method through a key down function or something of the sort.

    Sorry that I can't be of much help but I saw no one had chimed in yet so I thought I'd get you started. Maybe try to get something going with my info above and then post in the javascript forum for some additional help (once you have something to show).

    HTH

  3. #3
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Thanks Medyman,

    I will give that a shot and see what I come up with.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •