Jump to content

Help! HTML Calculation for PayPal


ForwardIT

Recommended Posts

Hi there.

I have been wandering around the tutorials and examples and trying to get a simple variable calculation done in the html code below but can't seem to get it right.

The html code below works fine now to create a button for PayPal and submit an order.
The problem is, I need the "amount_2" to actually be calculated to 2% of "amount_1".
a simple, "amount_2" = "amount_1" * 0.02
This is to allow us to take payment with PayPal and add their merchant fees.

Can anyone help please :-)


------------------------------------------
<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="accounts@freelanceswitch.com">
<input type="hidden" name="currency_code" value="AUD">
<input type="hidden" name="item_name_1" value="My Invoice">
<input type="hidden" name="amount_1" value="1885.00">
<input type="hidden" name="item_name_2" value="Merchant Fee">
<input type="hidden" name="amount_2" value="9999">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
------------------------------------------

Link to comment
Share on other sites

Got it ! Yay. Thank you Pandy !!!

 

<!DOCTYPE html>
<html>
<body>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="pp" onsubmit="addFee()">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="accounts@freelanceswitch.com">
<input type="hidden" name="currency_code" value="AUD">
<input type="hidden" name="item_name_1" value="My Invoice">
<input type="hidden" name="amount_1" value="1885.00">
<input type="hidden" name="item_name_2" value="Merchant Fee">
<input type="hidden" name="amount_2" value="">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and

secure!">
</form>


<script>
function addFee()
{
// Get the price of the item
var baseprice = document.forms['pp'].elements['amount_1'].value;

// Calculate the fee
var fee = 0.02 * baseprice;

// Set the value of the amount_2 field to the fee
document.forms['pp'].elements['amount_2'].value = fee;

// Makes sure the form submits
return true;
}
</script>

</body>
</html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...