TOPIC:

PayPal calculate amount based on selection 11 years 2 weeks ago #9993

  • TheMuffinMan's Avatar Topic Author
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 806
Make sure you read the multiple prices howto first:
www.crosstec.org/forums/15-usage/5303-pa...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;
   }
}
The following user(s) said Thank You: wartime

Please Log in or Create an account to join the conversation.

Re: PayPal calculate amount based on selection 10 years 11 months ago #10493

  • spencelk's Avatar
  • spencelk
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 76
  • Thanks: 9
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??
The following user(s) said Thank You: wartime

Please Log in or Create an account to join the conversation.

Re: PayPal calculate amount based on selection 10 years 11 months ago #10514

  • TheMuffinMan's Avatar Topic Author
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 806
Hi spencelk,

that needs some custom js code. What do you have so far?
The following user(s) said Thank You: wartime

Please Log in or Create an account to join the conversation.

Re:PayPal calculate amount based on selection 10 years 11 months ago #10519

  • spencelk's Avatar
  • spencelk
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 76
  • Thanks: 9
I am just starting to work with javascript so beware the syntax maybe wrong :unsure:
<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
The following user(s) said Thank You: wartime

Please Log in or Create an account to join the conversation.

Re:PayPal calculate amount based on selection 10 years 11 months ago #10531

  • TheMuffinMan's Avatar Topic Author
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 806
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';
The following user(s) said Thank You: wartime

Please Log in or Create an account to join the conversation.

Re:PayPal calculate amount based on selection 10 years 11 months ago #10554

  • spencelk's Avatar
  • spencelk
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 76
  • Thanks: 9
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?
The following user(s) said Thank You: wartime

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.052 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!