...

View Full Version : Character count without spaces and multiply result



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

Thanks,
Jesse

Kakao
05-07-2006, 05:37 PM
<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>

mensa_dropout
05-07-2006, 05:44 PM
<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>

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

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum