Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Character count without spaces and multiply result

    I need help in trying to figure out how to do a character count without the spaces being counted. Then, I would like to multiply the response by $0.50 and add that amount to the total price. I have a website where someone can add personalization to a blanket. Currently I have it set up in manual, but I am having trouble with orders being processed with personalization, but without adding the additional cost. Here is a link to my webpage: http://photo2blanket.com/color.html

    I have searched and tried many different codes without success. My other option would be to return a false statement in case the customer added some text in the personalization, but didn't add the additional cost for it.

    Thanks,
    Jesse

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function count(text) {
      return text.replace(/\s/g, '').length * 0.5;
      }
    </script>
    </head>
    <body onload="alert(count('ab cd ef '));">
    </body>
    </html>

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <HTML>
    <HEAD>
    
    <script type="text/javascript">
    function priceCount() {
    var output = '';
    var embroidery = document.getElementById("txtMessage").value;
    var nospaces = embroidery.replace(/ /g,'');
    var price = .5 * nospaces.length;
    var output = "message = " + embroidery + "\n"
    	   + "without spaces = " + nospaces + "\n"
    	   + "letter count = " + nospaces.length + "\n" 
    	   + "price = $" + price; 
    document.getElementById("results").innerText = output;
    }
    </script>
    
    </HEAD>
    enter your personalized message:
    <p/>
    <input type=text id="txtMessage" size=40/>
    <p/>
    <button onclick="priceCount()">get price count</button>
    <p>
    <div id="results"></div> 
    </HTML>

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mensa dropout and kakao thanks for the quick responses.

    mensa dropout, yours is very close to what I am trying to do. I forgot to mention that I am using PayPal as my processor (not sure if that makes much difference or not). I have tried your script and it works just as described. Is there a way to change that a little so that it will automatically be added to the "baseamt" value without having to do the pricecount button? I have tried to make some changes to get it do this, but was unable. Thanks again for the help.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    <input type=text id="txtMessage" size=40 onblur="priceCount();" />
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks felgall, onblur works fine. How do I get the results ($) added to the total cost of the item automatically?
    Thanks,
    Jesse


  •  

    Posting Permissions

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