Results 1 to 8 of 8

Thread: Javascript help!

  1. #1
    Sublime HEXUS.net
    Join Date
    Jul 2003
    Location
    The Void.. Floating
    Posts
    11,819
    Thanks
    213
    Thanked
    233 times in 160 posts
    • Stoo's system
      • Motherboard:
      • Mac Pro
      • CPU:
      • 2*Xeon 5450 @ 2.8GHz, 12MB Cache
      • Memory:
      • 32GB 1600MHz FBDIMM
      • Storage:
      • ~ 2.5TB + 4TB external array
      • Graphics card(s):
      • ATI Radeon HD 4870
      • Case:
      • Mac Pro
      • Operating System:
      • OS X 10.7
      • Monitor(s):
      • 24" Samsung 244T Black
      • Internet:
      • Zen Max Pro

    Javascript help!

    Right peeps, further to this tracking cookies thingy..

    They want a unique reference number and amount for every sale, the unique reference isn't a problem, but the tracker will only accept a numerical value for the amount, and our booking pages output the amount in the form "£199.99" as a nice big string..

    Our booking pages are almost entirely javascript as well, which is.. umm.. fun..

    Anyhoo, will the following strip off the £ character, leaving me with just the number?

    Code:
    <script language="JavaScript">
    var str_cost = "[!holiday_cost]";
    str_cost = replace(str_cost, "£,");
    </script>
    Leaving me to input the [!str_cost] into the tracking code?
    (\__/)
    (='.'=)
    (")_(")

  2. #2
    Member
    Join Date
    Jun 2004
    Posts
    61
    Thanks
    0
    Thanked
    0 times in 0 posts
    Stoo have you thought of:

    Code:
    <script>
       //... other code
       var str_cost = "[!holiday_cost]";
       
       str_cost = stripCharacter(str_cost,'£');
       //... and so on
    
    
    </script>
    This should remove every instance of £ from an input string, from memory.

  3. #3
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    i couldnt get that to work kirkabus

    when i do string replacement in JavaScript i use Regular Expressions....
    Code:
    <script language="JavaScript">
        var szSubject = "£89.99"
        var re = new RegExp("£", "g");
        var szResult = szSubject.replace(re, '');
        alert(szResult);
    </script>
    HTH

  4. #4
    Sublime HEXUS.net
    Join Date
    Jul 2003
    Location
    The Void.. Floating
    Posts
    11,819
    Thanks
    213
    Thanked
    233 times in 160 posts
    • Stoo's system
      • Motherboard:
      • Mac Pro
      • CPU:
      • 2*Xeon 5450 @ 2.8GHz, 12MB Cache
      • Memory:
      • 32GB 1600MHz FBDIMM
      • Storage:
      • ~ 2.5TB + 4TB external array
      • Graphics card(s):
      • ATI Radeon HD 4870
      • Case:
      • Mac Pro
      • Operating System:
      • OS X 10.7
      • Monitor(s):
      • 24" Samsung 244T Black
      • Internet:
      • Zen Max Pro
    Quote Originally Posted by kirkabus
    Stoo have you thought of:

    Code:
    <script>
       //... other code
       var str_cost = "[!holiday_cost]";
       
       str_cost = stripCharacter(str_cost,'£');
       //... and so on
    
    
    </script>
    This should remove every instance of £ from an input string, from memory.

    aha, after a quick google it's actually a custom built function..

    function stripCharacter(words,character) {
    //documentation for this script at http://www.shawnolson.net/a/499/
    var spaces = words.length;
    for(var x = 1; x<spaces; ++x){
    words = words.replace(character, "");
    }
    return words;
    }
    (\__/)
    (='.'=)
    (")_(")

  5. #5
    Sublime HEXUS.net
    Join Date
    Jul 2003
    Location
    The Void.. Floating
    Posts
    11,819
    Thanks
    213
    Thanked
    233 times in 160 posts
    • Stoo's system
      • Motherboard:
      • Mac Pro
      • CPU:
      • 2*Xeon 5450 @ 2.8GHz, 12MB Cache
      • Memory:
      • 32GB 1600MHz FBDIMM
      • Storage:
      • ~ 2.5TB + 4TB external array
      • Graphics card(s):
      • ATI Radeon HD 4870
      • Case:
      • Mac Pro
      • Operating System:
      • OS X 10.7
      • Monitor(s):
      • 24" Samsung 244T Black
      • Internet:
      • Zen Max Pro
    Quote Originally Posted by Stoo
    aha, after a quick google it's actually a custom built function..

    function stripCharacter(words,character) {
    //documentation for this script at http://www.shawnolson.net/a/499/
    var spaces = words.length;
    for(var x = 1; x<spaces; ++x){
    words = words.replace(character, "");
    }
    return words;
    }
    and it still didn't work..

    Using rubbishrubbishrubbishrubbishrubbishey's method..

    will report back shortly (cos I'm not very tall )
    (\__/)
    (='.'=)
    (")_(")

  6. #6
    Sublime HEXUS.net
    Join Date
    Jul 2003
    Location
    The Void.. Floating
    Posts
    11,819
    Thanks
    213
    Thanked
    233 times in 160 posts
    • Stoo's system
      • Motherboard:
      • Mac Pro
      • CPU:
      • 2*Xeon 5450 @ 2.8GHz, 12MB Cache
      • Memory:
      • 32GB 1600MHz FBDIMM
      • Storage:
      • ~ 2.5TB + 4TB external array
      • Graphics card(s):
      • ATI Radeon HD 4870
      • Case:
      • Mac Pro
      • Operating System:
      • OS X 10.7
      • Monitor(s):
      • 24" Samsung 244T Black
      • Internet:
      • Zen Max Pro
    Rar! it worketh

    Had to modify things a bit to add a doc.write, but it works okay

    Cheers matey
    (\__/)
    (='.'=)
    (")_(")

  7. #7
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    no problemo

  8. #8
    Member
    Join Date
    Jun 2004
    Posts
    61
    Thanks
    0
    Thanked
    0 times in 0 posts
    Bah, must learn to test code before posting. I'd agree with rubbishrubbishrubbishrubbishrubbishey regex is by far more efficient.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Poss javascript type error in posts
    By Kumagoro in forum General Discussion
    Replies: 1
    Last Post: 03-12-2004, 08:24 AM
  2. Javascript problem
    By Korky in forum PC Hardware and Components
    Replies: 0
    Last Post: 03-04-2004, 12:58 AM
  3. Javascript Help
    By Basher in forum Software
    Replies: 5
    Last Post: 23-01-2004, 10:30 AM
  4. Replies: 1
    Last Post: 14-08-2003, 03:32 PM

Posting Permissions

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