473,837 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript" type="text/javascript">

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

function item2_Tally(){
if(document.car t2.quantity.val ue >= 10){
document.cart2. amount.value = 1;
}else if(document.car t2.quantity.val ue < 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@mydom ain.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@mydom ain.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 2147
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="JavaS cript" type="text/javascript">

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

}

function item2_Tally(){
if(document.car t2.quantity.val ue >= 10){
document.cart2. amount.value = 1;
}else if(document.car t2.quantity.val ue < 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
1736
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 similar) integration. I've read up on PayPal's site about integrating their API and suck, but as of yet no practical experience. Has anyone out there had experience doing this? Is it the best bet? Successes, failures, anything would be appreciated....
2
3320
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 storing the necessary product information. There could be several fields involved... Then there ought to be another javascript method that can create a new document based on the list a user has built selecting product from several
1
3589
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 be able to come along and add it to their shopping cart. thanks joy
7
2586
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, meaning that any rank novice can click the Buy button on your site, then when the PayPal page loads, change the amount for the transaction and press Enter. This reloads the page with the new amount. This is so obvious that anyone could do it.
3
1729
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, printed then mailed off with payment.... what I would really like to do, to improve this greatly - would be to simulate what a paypal "add to cart" button would do - which is click to add an item, and it places that item in a window in a...
5
2744
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 insecure as could be. Therefore why not use a POST and hide them in hidden variables? Well I would if I could figure it out. The contents of the cart are created dynamically and since I already have a button on my form that needs to be captured by...
3
8042
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 action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="seller@designerfotos.com"> <input type="hidden" name="item_name"
1
2109
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 for my customer. I found some PayPal ASP.Net controls to be used with .net studio. Basically, I want the user to be able to shop on my website, add items to my shopping cart and at the checkout to be taken to the PayPal website. I would like...
3
2029
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 that info to a database. I'm proficient at ASP coding but not sure how to handle this.
0
9694
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10639
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10286
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7824
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.