473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PayPal shopping cart forms and JavaScript

I am designing a PayPal shopping cart/store for a client and have placed
several of PayPal's shopping cart forms on the page to correspond with
different products. Each form has a unique name though each of the
form's elements have to use PayPal's required naming conventions to pass
the data to their server.

Many of the forms have hard-coded data in them and these have not caused
me any problems. The problems I am having are with 3 forms that need to
send different amounts based on the quantity ordered. I wrote a small
function that worked great on the 1st form but when I created the 2nd
form and wrote the 2nd function, all of the forms that needed to send
conditional amounts broke down and wouldn't work any more.

In any case, I created a simple page to troubleshoot the problem and am
having the same troubles. Please let me know if you can see why they
won't work properly.

Here are my 2 functions:

<script language="JavaScript" type="text/javascript">

function item1_Tally(){
if(document.cart1.quantity.value < 6){
document.cart1.amount.value = 1;
}else if(document.cart1.quantity.value > 5){
document.cart1.amount.value = 2;
}

function item2_Tally(){
if(document.cart2.quantity.value >= 10){
document.cart2.amount.value = 1;
}else if(document.cart2.quantity.value < 10){
document.cart2.amount.value = 3;
}
}
</script>

Here is the very simplified html for the forms. I suspect that since the
2 forms here share elements with identical names, this could be part of
my problem:

<form id="cart1" name="cart1">
<input name="cmd" type="hidden" value="_cart">
<input name="business" type="hidden" value="me@mydomain.com">
<input name="item_name" type="hidden" value="item1"></h2>
Quantity: <input name="quantity" type="text" size="3" maxlength="3"
value="0">
Amount: <input type="text" name="amount" size="3" maxlength="3"><br>
<input name="tally" type="button" value="Go" onclick="item1_Tally();">
</form>

<form id="cart2" name="cart2">
<input name="cmd" type="hidden" value="_cart">
<input name="business" type="hidden" value="me@mydomain.com">
<input name="item_name" type="hidden" value="item1">
Quantity: <input name="quantity" type="text" size="3" maxlength="3"
value="0">
Amount: <input type="text" name="amount" size="3" maxlength="3"><br>
<input name="tally" type="button" value="Go" onclick="item2_Tally();">
</form>

Here is a link for a better understanding:
http://www.hannon-illustration.com/j...ypalForms.html

Thanks,

Mark
Jul 23 '05 #1
2 2090
Mark Hannon wrote:
[...]

Many of the forms have hard-coded data in them and these have not caused
me any problems. The problems I am having are with 3 forms that need to
send different amounts based on the quantity ordered. I wrote a small
function that worked great on the 1st form but when I created the 2nd
form and wrote the 2nd function, all of the forms that needed to send
conditional amounts broke down and wouldn't work any more.
You're missing a closing brace (see below).

In any case, I created a simple page to troubleshoot the problem and am
having the same troubles. Please let me know if you can see why they
won't work properly.

Here are my 2 functions:

<script language="JavaScript" type="text/javascript">

function item1_Tally(){
if(document.cart1.quantity.value < 6){
document.cart1.amount.value = 1;
}else if(document.cart1.quantity.value > 5){
document.cart1.amount.value = 2;
}
^------- You've closed the if, but not the function.

}

function item2_Tally(){
if(document.cart2.quantity.value >= 10){
document.cart2.amount.value = 1;
}else if(document.cart2.quantity.value < 10){
document.cart2.amount.value = 3;
}
}
</script>

Here is the very simplified html for the forms. I suspect that since the
2 forms here share elements with identical names, this could be part of
my problem:


Identical names are valid in HTML, identical IDs are not. Also, names
should not match IDs as they share the same namespace.

The scope of a name in a form is the form, so your naming (as far as I
can tell) is fine. Just fix the missing brace.

You need to be careful with duplicate names. Referencing form elements
by name can return a collection or an element, attempting to access:

document.formA.elementA[0].value

when it's not a collection will return 'undefined' and:

document.formA.elementA.value

will have similar results if ...elementA is a collection (i.e. there
are two or more elements with the name 'elementA' in 'formA').
[...]

--
Rob
Jul 23 '05 #2
Rob

Thanks for the observation on the missing bracket. I was stunned to see
both forms worked as expected when I fixed it.

For some reason, with the paypal shopping cart I was working on, I
would create a form get it working, and move on to the next form. As
soon as I got the next form working, the first one stopped working.
Since my simple test works so well it has done nothing toward helping
me identify the problem.

Mark

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lunchbox G4 | last post by:
I am working on a site, and the people its for are asking about a way of collecting money online. Doing an onsite shopping cart is not a possibility right now, so I'm looking towards PayPal (or...
2
by: Paul Bruneau | last post by:
Hi, I hope someone can help me make a working shopping cart, as a learning tool. If I have a "Product Demo" html page with a "Buy Me" button, there must be a simple javascript method of...
1
by: madison | last post by:
Hi, I am trying to start a website using paypals shopping cart function. If i have 10 items and they sell out, how do I make it so the item is then listed as sold out. The next person would not...
7
by: Alan Silver | last post by:
Hello, I've just been looking at the free PayPal component from ComponentOne and am somewhat amazed how insecure it is. They include all the transaction details in plain text in the querystring,...
3
by: neutrino | last post by:
Hi, I'v created a site for client, with several pages of products for sale, we're not using any Online payment method yet -so in the meantime, I'v just provided an Order Form, to be completed,...
5
by: Jason James | last post by:
Guys, it seems that several people have enquired about how to communicate with Paypal as securely as possible. It is obvious that placing the shopping cart details in the URL is about as...
3
by: Yourself | last post by:
Hi, I'm trying to post data to PayPal for a shopping cart, basically I want to replicate a form like the following, but create the variables dynamically from code behind: <form...
1
by: Vahehoo | last post by:
Hi, I have an ASP .Net e-business site that is built using DNN 2.0. I am having troubles passing my shopping cart items to PayPal. I implemented a total paynow button, but it was not good enough...
3
by: mikelindsey | last post by:
Hello, I have standard Paypal "Add to Cart" buttons. I don't have a shopping cart on my site I use the Paypal shopping cart. I'd like to track when a user clicks on the "Add to Cart" and save...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.