Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2006, 05:09 PM   PM User | #1
jesnamy
New to the CF scene

 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jesnamy is an unknown quantity at this point
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
jesnamy is offline   Reply With Quote
Old 05-07-2006, 05:37 PM   PM User | #2
Kakao
Regular Coder

 
Join Date: Mar 2006
Location: Brasília, Brazil
Posts: 153
Thanks: 0
Thanked 0 Times in 0 Posts
Kakao is on a distinguished road
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>
Kakao is offline   Reply With Quote
Old 05-07-2006, 05:44 PM   PM User | #3
mensa_dropout
New Coder

 
Join Date: May 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
mensa_dropout is an unknown quantity at this point
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>
mensa_dropout is offline   Reply With Quote
Old 05-07-2006, 07:05 PM   PM User | #4
jesnamy
New to the CF scene

 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jesnamy is an unknown quantity at this point
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.
jesnamy is offline   Reply With Quote
Old 05-07-2006, 10:40 PM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
<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/
felgall is offline   Reply With Quote
Old 05-09-2006, 06:27 PM   PM User | #6
jesnamy
New to the CF scene

 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jesnamy is an unknown quantity at this point
Thanks felgall, onblur works fine. How do I get the results ($) added to the total cost of the item automatically?
Thanks,
Jesse
jesnamy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:16 PM.


Advertisement
Log in to turn off these ads.