Welcome, Guest

PayPal calculate amount based on selection
(1 viewing) (1) Guest

TOPIC: PayPal calculate amount based on selection

PayPal calculate amount based on selection 2 years, 6 months ago #9993

Make sure you read the multiple prices howto first:
www.crosstec.de/forums/15-usage/5303-pay...multiple-prices.html

If you want to calculate prices based on a multiplier/selection, use the code below for your PayPalSelect element.
In the element's options (advanced tab in QuickMode) scroll to the action script section and check "change", then select "custom".

In the codebox, paste the code below.

Note the comments that start with // in the code
Very important is that you enter the prices and taxes corresponding to the PayPalSelect values!

The first element in your PayPalSelect should contain a "please choose" message and not contain any prices.


function ff_PayPalSelect_action(element, action)
{
    switch (action) {
        case 'change':
	    if(element.selectedIndex > 0)
	    {
		// price|tax corresponding to the PayPalSelect values
	    	var prices = ['60|3', '100|5'];

		// name of the select or textfield that holds the multipliers
		var howmanyName = 'howmany';

                var howmany  = ff_getElementByName(howmanyName).options[ ff_getElementByName(howmanyName).selectedIndex ].value;
		// or use this if you use a textfield for the multiplier instead of a select, in that case, comment the line above and uncomment below
                // var howmany  = ff_getElementByName(howmanyName).value;

		// calulations and re-assignment of prices and taxes
	    	var val = prices[ element.selectedIndex - 1 ];
		var splitted = val.split('|');
                var result = Number( splitted[0] ) * Number( howmany );
		var taxes  = Number( splitted[1] ) * Number( howmany );
		var selector = element.options[ element.selectedIndex ].value.split('|');
		element.options[ element.selectedIndex ].value = selector[0] + '|' + selector[1] + '|' + result + '|' + taxes;
	    }
            break;
        default:;
    } // switch
} // ff_PayPalSelect_action



Tip:

If someone is selecting the amount AFTER he selected from the PayPalSelect, make sure the PayPalSelect is set back to its initial state. This will make sure that the correct price is calculated.

This can be done with this action code for the amount selection (onchange as well):


function ff_ELEMENTNAME_action(element, action)
{
    switch (action) {
        case 'change':
        // setting back PayPalSelect to initial state
        ff_getElementByName('PayPalSelect').selectedIndex = 0;
        break;
   }
}

===============================================
Satisfied?
Consider a membership!
===============================================
Like us on Facebook
===============================================
Follow us on Twitter
===============================================

Re: PayPal calculate amount based on selection 2 years, 5 months ago #10493

Hello Muffin Man!

What I would like to do is based upon a checkbox being checked I would like to add to the price of my service. example, original cost is $100 then payment is done via paypal (that's the easy part) but if they check a box I want the cost to be $200 and if another box then $300 and so on. Is this possible??
  • spencelk
  • OFFLINE
  • Senior Boarder
  • Posts: 78
  • Karma: 0

Re: PayPal calculate amount based on selection 2 years, 5 months ago #10514

Hi spencelk,

that needs some custom js code. What do you have so far?
===============================================
Satisfied?
Consider a membership!
===============================================
Like us on Facebook
===============================================
Follow us on Twitter
===============================================

Re:PayPal calculate amount based on selection 2 years, 5 months ago #10519

I am just starting to work with javascript so beware the syntax maybe wrong

<script type="text/javascript">

function paypaySetAmountValue()

var addVenue1 = document.getElementById('addVenue1')
var addVenue2 = document.getElementById('addVenue2')
var addVenue3 = document.getElementById('addVenue3')
var addVenue4 = document.getElementById('addVenue4')

if (addVenue1 == !checked && addVenue2 == !unchecked && addVenue3 == !unchecked && addVenue4 == !unchecked)
  {
  paypal.amount.value == "469.95";
  }
  
else if (addVenue1 == !checked && addVenue2 == !checked && addVenue3 == !unchecked && addVenue4 == !unchecked)
  {
  paypal.amount.value == "694.95";
  }
else if (addVenue1 == !checked && addVenue2 == !checked && addVenue3 == !checked && addVenue4 == !unchecked)
  {
  paypal.amount.value == "919.95";
  }
else if (addVenue1 == !checked && addVenue2 == !checked && addVenue3 == !checked && addVenue4 == !checked)
  {
  paypal.amount.value == "1144.95";
  }
  
else 
  {
  paypal.amount.value == "244.95"  
  
</script>


I am hoping that this code will allow me to keep just a standard paypal button without using the paypal select
  • spencelk
  • OFFLINE
  • Senior Boarder
  • Posts: 78
  • Karma: 0

Re:PayPal calculate amount based on selection 2 years, 5 months ago #10531

Hi,

settings the value by js would be like that:

1. Create a hidden element with the name (not title!) "PayPalSelect"
2. If you need to change the price, change element's value like this:

ff_getElementByName("PayPalSelect").value = 'Itemname|Itemnumber 1|244.95|0';
===============================================
Satisfied?
Consider a membership!
===============================================
Like us on Facebook
===============================================
Follow us on Twitter
===============================================

Re:PayPal calculate amount based on selection 2 years, 5 months ago #10554

Where would I put this code:

ff_getElementByName("PayPalSelect").value = 'Itemname|Itemnumber 1|244.95|0';

Will I need the code then I wrote above? If so, where would that go?
  • spencelk
  • OFFLINE
  • Senior Boarder
  • Posts: 78
  • Karma: 0
Moderators: TheMuffinMan, ForumSupport
Time to create page: 1.16 seconds

Facebook Discount - 40% Off!

Fans of our Facebook page here are entitled to get a 1-year-subscription for the price of a 6-months!

Steps to take:

  • Become a fan on Facebook (Like) here
  • Purchase a 6-months-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of your like and we'll upgrade to the 1-year-subscription

Joomla!® Forms Discount - 40% Off!

Already purchased a forms extension from a different vendor but your requirements changed and now you need a forms extension that is capable of more than just the standards? We help you to keep the costs for a change under control: Get a 40% discount on our professional membership plan! -- meaning timely unlimited access to all current and future commercial extensions, breezingforms themes & apps and Joomla!® templates at crosstec.de, including 1 year of support -- without any website limitations -- Just prove that you previously purchased another forms extension for Joomla!® from a different vendor and you are qualified.

Steps to take:

  • Purchase a 1-year-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of the purchase for the other form vendor and we'll upgrade to the professional-subscription

About

Crosstec GmbH & Co. KG

Bergisch-Gladbacher-Str. 829

51069 Cologne, Germany

Imprint