View Full Version : Can Javascript add something to a shopping cart?

Patrick Robinso
05-23-2005, 10:02 PM
I read the guidelines for posting. Did a search and did not find the answer to my problem. Any help would be most appreciated.

Please look at this page:


It's a classified ad order form page. It uses Mal's E-com at the bottom of the page.
A user clicks on the ad type of their choice (3 line, 4 line and so on) and the Mal's E-com page opens to show them what their cost is.

HERE'S the problem.

If you look about halfway down the page you will see the button to
ADD SPECIAL ATTENTION GETTING CHARACTERS. This opens a small window that shows these characters. I need to have a value of "Fifty Cents" show up in the FINAL Mal's E-Com page but ONLY after the end user clicks the button at the bottom of the page. In other words..THIS portion of the purchase should NOT open the Mal's ecom page (the user should stay on the order form page)...but SHOULD show up in the total. Mal's will add a cumulative total so that's ok.
I paid a developer to create the symbol picker script...and it works just fine, putting the number in the text box. But it does NOT currently add fifty cents to the total cost of the ad.

HOW CAN THIS BE ACCOMPLISHED? PLEASE!!!! I am truly stuck here!!!

Patrick Robinson

05-23-2005, 10:54 PM

I know you have more code than would be reasonable to post. From your narrative, I'm not sure if EACH special character costs an additional fifty cents. I assumed not, because you didn't specifically state so.

The code below, onsubmit, tests whether there is at least one special character in that textarea, and if so, it inserts .5 into a hidden form field.

I don't know what happens next. But, I'll assume that all of your form data is sent to a summary page. To add the fifty cents, you'll need to convert it to a number, from a string by:

extraFee = parseFloat(isForm.specCharFee.value);

You can then add it to your total.

<Script Language=JavaScript>

function testAddlFee(isForm){

isChar = isForm.specialChar.value;
if (isChar != ""){isForm.specCharFee.value = ".5"}

<Form name='orderForm' onsubmit="testAddlFee(this)">
<textarea name='specialChar' rows=10 cols=15>#17</textarea>
<input type=hidden name='specCharFee'>
<input type=submit value='Submit'>

Patrick Robinso
05-23-2005, 11:14 PM
Thanks for your reply Mike...Most appreciated.

What I don't really understand is this:

How does the number...that fifty cents...get sent to the e-commerce shopping cart so that it adds to the total?

If you go to the page, click on the "3 line ad" button it opens the E-com page
and shows you the total. If you hit the browser "back" button and click on the same button again...it adds to the total. SO...what I'm hoping to have happen is for the end user to click on a special character and have that add Fifty cents to their total cost WITHOUT opening the e-com page until they choose
a button at the bottom.

Thanks again for any help you can provide.

05-23-2005, 11:46 PM

I see now that your "summary" page is .cfm type. You are not going to be able to edit that to add the fifty cents. And to pay the authors of the code to make that modification... well, if were me, I'd be thrilled to sell ads, and I'd "eat" the fifty cents, or bump up the other rates by a nickel.

JavaScript can't help you with this.

05-24-2005, 12:09 AM
The price can be submitted by adding the .50 to the hidden inputs in the various payment forms at the bottom of the page.
It looks like the author of the popup window tried to do it , but there are errors in the conditionals and regular expressions that fail and the n_price variable in the function does not appear to have a value.

But, just as the special characters numbers are added to the textarea, the math to add the .50 cents can also be done.

The only requirement in all this is the browser must support and have Javascript turned on, which is assumed by the script.


Patrick Robinso
05-24-2005, 12:19 AM
Thank you Mike....

My knowledge of Javascript is terribly limited but I understand that this type of page cannot be edited. For future reference can you tell me what type CAN be edited or recommend a good shopping cart for use for the type of application the newspaper needs?


05-24-2005, 12:46 AM

To my knowledge, if your host supports it, .php files can contain JavaScript, and of course, .htm and .html. You can check the details of your hosting account for the server-side languages it supports.

Although, I haven't made any effort to learn it, others have told me that PHP is fairly easy to learn, easier than JavaScript.

My host, godaddy.com has an add-on feature for $9.95 month to quickly and easily implement PayPal's shopping cart. No coding necessary. Of course, you could also spend time with PayPal's 100 page manual and attempt to implement the shopping cart on your own.

Maybe you just need to find another host. Many hosts have add-on shopping carts. But, with PayPay, at least you know what you are getting. It's secure, and I've never heard any complaints about it.

And, I'm sure you've seen it. PayPal has the "Buy Now" button. That's what I use on my site. If you don't want to deal with a shopping cart, you can have multiple "Buy Now" buttons. You CAN implement that on your own, without much difficulty.

Anyway, good luck to you.