• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 981
  • Last Modified:

need to increase paypal subscription amount by total quantity

i am trying to create a paypal form where the total subscription cost is dependent on the quantity of "like" subscriptions ordered ...

i.e., all subscriptions are a set price, say 80.00, but a person can choose 1, 2, 3, etc subscriptions
i have tried PayPal's HTML variables for "amount" of: amount, amount3, a3 and cannot get my javascript towork

<body>
<script type="text/javascript">
<!--
function CalculateOrder(form)
{
var newamt number;
var os2=document.getElementById("os2").value;

if os2 == "1 share" {
newamt = 80.00 }
if os2  == "2 shares" {
newamt = 160.00 }
if os2  == "3 shares" {
newamt = 240.00 }
if os2  == "4 shares" {
newamt = 320.00 }
if os2  == "5 shares" {
newamt = 400.00 }
document.write(os2)
document.write(newamt)
}
//-->
</script>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="12345678">
<table>
<tr><td>
<input type="hidden" name="on0" value="Usernames">Usernames</td></tr>
<tr><td><input type="text" name="os0" maxlength="60"></td></tr>
<tr><td>
<input type="hidden" name="on1" value="Your Email ">Your Email</td></tr>
<tr><td><input type="text" name="os1" maxlength="60"></td></tr>

<tr><td>
<input type="hidden" name="on2" value="Number of Shares"></td>
<tr><td align="left"><select name="os2">
      <option value="1 share">1 share $80.00</option>
      <option value="2 shares">2 shares $160.00</option>
      <option value="3 shares">3 shares $240.00</option>
      <option value="4 shares">4 shares $320.00</option>
      <option value="5 shares">5 shares $400.00</option>
</select> </td></tr>
 <input type="hidden" name="a3" value="document.write(newamt);">
 <input type="hidden" name="amount3" value="document.write(newamt);">


</table>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0"

name="submit" alt="" onClick="CalculateOrder(this.form)">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

thank you for any clarification you can provide that i'm missing ...
0
allcoder
Asked:
allcoder
  • 5
  • 4
3 Solutions
 
apexpertCommented:
0
 
vinod364Commented:
I guess you mean you want to write down the total price once user clicks on the button ?
Assuming this is the case, you need to change this line
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0"
name="submit" alt="" onClick="CalculateOrder(this.form)">
with this one
<img src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0"
name="submit" alt="" onClick="CalculateOrder(this.form)">
Since whenever user clicks on the button image your form is getting submitted automatically since the property of the image is set as "input type"
So in the new scenario you manually need to submit the form after this line
"document.write(newamt)"

0
 
allcoderAuthor Commented:
i changed the "Submit" button to the   <img src=  suggestion, and then after then i altered the javascript code to:
document.write(newamt)
  document.CoopForm.submit() ;

where <form name="CoopForm" action="https://www.paypal.com/cgi-bin/webscr" method="post">

but now, the form is not triggering to PayPal at all, and the document.write commands are not displaying anything to the browser ...

ideas ???
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
vinod364Commented:
change all of your code with this one
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body>

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

function CalculateOrder(form)
{
var newamt ;
var os2=document.getElementById("os2").value;

if (os2 == "1 share") {
newamt = 80.00 }
if (os2  == "2 shares") {
newamt = 160.00 }
if (os2  == "3 shares") {
newamt = 240.00 }
if (os2  == "4 shares") {
newamt = 320.00 }
if (os2  == "5 shares") {
newamt = 400.00 }
var el = document.getElementById("totalPrice");
if(el){
el.innerHTML = os2 + " " + newamt;
}
//document.write(os2);
//document.write(newamt);
document.CoopForm.submit();
}

</script>

<form id="CoopForm" name="CoopForm" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="12345678">
<table>
<tr><td>
<input type="hidden" name="on0" value="Usernames">Usernames</td></tr>
<tr><td><input type="text" name="os0" maxlength="60"></td></tr>
<tr><td>
<input type="hidden" name="on1" value="Your Email ">Your Email</td></tr>
<tr><td><input type="text" name="os1" maxlength="60"></td></tr>

<tr><td>
<input type="hidden" name="on2" value="Number of Shares"></td>
<tr><td align="left"><select id="os2" name="os2">
      <option value="1 share">1 share $80.00</option>
      <option value="2 shares">2 shares $160.00</option>
      <option value="3 shares">3 shares $240.00</option>
      <option value="4 shares">4 shares $320.00</option>
      <option value="5 shares">5 shares $400.00</option>
</select> </td></tr>
 <input type="hidden" name="a3" value="document.write(newamt);">
 <input type="hidden" name="amount3" value="document.write(newamt);">
<tr><td>Total Price: <span id="totalPrice"></span></td></tr>

</table>
<img src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit1" alt="" onClick="CalculateOrder(this.form)">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
  </body>
</html>


This will submit your form to paypal and also display the price at the bottom of the page just above the submit button
0
 
allcoderAuthor Commented:
thanks .... identifying the Form and select clause with the id= were definitely something that an extra set of eyes helped with ...

form id="CoopForm" name="CoopForm"
<select id="os2" name="os2">

but ... in trying to pass the subscription value for a3 of newamt, i cannot get that to pick up regardless of any configuration of quotes, non-statements, etc.
 <input type="hidden" name="a3" value="document.write(newamt);">
 <input type="hidden" name="amount3" value="document.write(newamt);">

can the a3 value be re-set?
0
 
vinod364Commented:
you can always reset these values just before the form submission statement e.g
var el1 = document.getElementById("a3");
if(el1){
  el1.value = "new_value";
}
before this statement
document.CoopForm.submit();


On a side note there were some other small errors in your script as well e.g
if os2 == "1 share"  should have been written like this if (os2 == "1 share" )
Also note down the new name of the image
name="submit1"
instead of name="submit" otherwise your statement " document.CoopForm.submit();" would have thrown errors
0
 
vinod364Commented:
sorry replace
var el1 = document.getElementById("a3");
if(el1){
  el1.value = "new_value";
}
in above code with this line
document.CoopForm.a3.value = "new_value";

0
 
allcoderAuthor Commented:
thank you .... i did catch the () around the os2 == "share values", and the submit -> submit1 change
if you will notice, i chose the handle "allcoder", as i bounce between javascript, php, SAS, Oracle, APEX, Pl/SQL, so yes, nuiances are a problem in the "wee hours of the a.m." ...

on that same note, please bear with me, your last note suggested that i only needed to add the line

document.CoopForm.a3.value = "new_value";      (which i translated to mean "newamt") to the javascript, and therefore, i would think, remove the document.write code of
 <input type="hidden" name="a3" value="document.write("newamt");">
 <input type="hidden" name="amount3" value="document.write("newamt");">

from the <form> portion  .... in doing so, the paypal transaction screen still DOES NOT resolve to the new amount of the increased value of the subscription cost if multiple shares are purchased ....

my thanks again ....

0
 
vinod364Commented:
I am assuming you mean by "paypal transaction screen " the url on the paypal website . right ?
If yes. First you need to make sure you are sending all parameters to paypal ? I don't think so. You should use javascript only for displaying values at the client side, however for all validations and redirections to the paypal website you should use a server side scripting language e.g PHP . As javascript is not secure enough.

Btw: I can't see other parameters that are required by paypal to process a transaction. May be that could be the issue. In any case Always use server side language for this kind of things. Javascript is simply not secure. It will show all important information to end users by clicking on view source link
0
 
allcoderAuthor Commented:
Using all of the "Expert Comment By: vinod364 ", I was able to modify my original code to get it to function, and ultimately pass the new coded value to PayPal.

I did not need to utilize php as suggested, but rather pass the resultant newamt value to the a3 variable as such ... for any others wishing to do so .....

document.CoopForm20.a3.value = newamt;
prior to the submit();

- allcoder
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now