View Full Version : Character count without spaces and multiply result

05-07-2006, 06:09 PM
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.


05-07-2006, 06:37 PM
<script type="text/javascript">
function count(text) {
return text.replace(/\s/g, '').length * 0.5;
<body onload="alert(count('ab cd ef '));">

05-07-2006, 06:44 PM

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

enter your personalized message:
<input type=text id="txtMessage" size=40/>
<button onclick="priceCount()">get price count</button>
<div id="results"></div>

05-07-2006, 08:05 PM
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.

05-07-2006, 11:40 PM
<input type=text id="txtMessage" size=40 onblur="priceCount();" />

05-09-2006, 07:27 PM
Thanks felgall, onblur works fine. How do I get the results ($) added to the total cost of the item automatically?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum