hopefully easy programming question

A

Andrea Chen

I'm new to this (2 days new) so please bear with me.
I want have a form & button working with a paypal order so that when
the user puts in the order quantity on my page, the javascript selects
the correct price based on quantity and sends those 2 numbers to
paypal.

I have no idea how to do this. I don't know if it should go in the
ShowPRice function or if it should be done in a form. Would someone
help me?

What I have written so far:

<html>
<head>
<script language="javascript" type="text/javascript">
<!--
function CalculatePrice(NumOrdered)
{
if (NumOrdered>=6 && NumOrdered<=10)
{var ItemPrice = 5.00 }
else if (NumOrdered >=11 && NumOrdered<=25)
{var ItemPrice = 4.50 }
else if (NumOrdered >=26 && NumOrdered<=80)
{var ItemPrice = 4.00 }
else if (NumOrdered> 80)
{var ItemPrice = 3.50 }
else if (NumOrdered< 6)
{alert("Minimum wholesale order is 6") ;
var ItemPrice = 5.00 }
else
{alert("You did not enter a number!");
var ItemPrice = 5.00}
return ItemPrice ;
}

function ShowPrice(NumOrdered)
{
var FinalPrice=CalculatePrice(NumOrdered);
alert("Price per unit: "+FinalPrice)
}

// -->
</script>
</head>

<body>

<***** now this form fm2a works very nicely and shows me the correct
<***** price
<form name="fm2a">
Enter quantity :
<input type="text" name="quantity">
<input type="button" name="dis" value="Add to Cart"
onClick='ShowPrice(document.fm2a.quantity.value)'>
</form>


<***** But what I really want is the button to do place a paypal
order,
<***** inserting the quantity ordered and the correct price. What
I've
<***** done here does not work.
<form name="submit" target="paypal"
action="https://www.paypal.com/cgi-bin/webscr" method="post">
Enter quantity :
<input type="text" name="quantity">
<input type="button" name="dis" value="Add to Cart"
onClick='ShowPrice(document.submit.quantity.value)'>
<input type="hidden" name="add" value=NumOrdered>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="(e-mail address removed)">
<input type="hidden" name="item_name" value="Wholesale item">
<input type="hidden" name="item_number" value="WRTH">
<input type="hidden" name="amount" value=FinalPrice>
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
</form>
</body>
</html>
 
A

Andrea Chen

Andrew Thompson said:
AFAIR, you do that at the PayPal end by setting up
different links to go to. You could then choose which
link with JS, or simply list the different products as
separate links..

They're not different products, just different quantities of the same
product. I think I need to have a Paypal store to do that (which I
don't...). I'll look into it, though.
 
L

Lee

Andrea Chen said:
I'm new to this (2 days new) so please bear with me.
I want have a form & button working with a paypal order so that when
the user puts in the order quantity on my page, the javascript selects
the correct price based on quantity and sends those 2 numbers to
paypal.

I have no idea how to do this. I don't know if it should go in the
ShowPRice function or if it should be done in a form. Would someone
help me?



I don't know much about PayPal. Maybe I'm wrong, but
unless you know that I'm wrong, you should reconsider
using client-side Javascript to compute your prices and
send the result off to be billed. There are a lot of us
out here who can read your code and make changes to it on
the fly so that the function sends PayPal whatever price
we happen to feel like paying.

Even if you're not actually committed to sell at the price
that PayPal receives, I'll bet that it's going to cost you
time and trouble (at least) to back out of the transaction.


Now that you know that you shouldn't do this, here's how:
<input type="hidden" name="amount" value=FinalPrice>

Apparently you were hoping that this line would set the
value of FinalPrice at the time of form submission. Since
that's an HTML line, it actually sets the value at the time
that the form is first displayed, and since HTML doesn't
know anything about variables, it sets the value to "FinalPrice".

The correct way to have your function set the value of the
hidden form field named "amount" is:

function ShowPrice(NumOrdered)
{
var FinalPrice=CalculatePrice(NumOrdered);
document.forms["submit"].elements["amount"].value=FinalPrice;
}

Note that this doesn't submit the form for you.
 
A

Andrea Chen

Lee said:
I don't know much about PayPal. Maybe I'm wrong, but
unless you know that I'm wrong, you should reconsider
using client-side Javascript to compute your prices and
send the result off to be billed. There are a lot of us
out here who can read your code and make changes to it on
the fly so that the function sends PayPal whatever price
we happen to feel like paying.

I have in fact tried it just to see if it could be done, and it can.
Copy the page source, tweak it and run it. Doesn't matter html or
javascript, if the prices are in the page source, anyone can mess with
it.
The correct way to have your function set the value of the
hidden form field named "amount" is:

function ShowPrice(NumOrdered)
{
var FinalPrice=CalculatePrice(NumOrdered);
document.forms["submit"].elements["amount"].value=FinalPrice;
}

Note that this doesn't submit the form for you.

I see. Thank you very much. I think though as you and Andrew said,
it's probably safer to have the prices locked somewhere else.

-andrea-
 
A

Andrea Chen

Charles Crume said:
You don't have to do anything of the sort. When the user clicks on the link,
the PayPal shopping cart page appears andyour customer can change the
*uantity field*there.

Ummm....Charles... I think you may have missed the point behind my
dipping into javascript. The *price* *changes* according to the
quantity ordered.

-andrea-
 
T

Thomas 'PointedEars' Lahn

Andrea said:
Lee [...] wrote [...]
I don't know much about PayPal. Maybe I'm wrong, but
unless you know that I'm wrong, you should reconsider
using client-side Javascript to compute your prices and
send the result off to be billed. There are a lot of us
out here who can read your code and make changes to it on
the fly so that the function sends PayPal whatever price
we happen to feel like paying.

I have in fact tried it just to see if it could be done, and it can.
Copy the page source, tweak it and run it. Doesn't matter html or
javascript, if the prices are in the page source, anyone can mess with
it.

It is much more simple. Consider something like

javascript:alert(document.forms[0].elements['foo'].value = 0.0042);

typed in the Location Bar ;-)


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top