• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Add tick box which adds 3% to total

Add tick box which adds 3% to total 1 month 3 weeks ago #43859

  • samier
  • samier's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
I have created a donation form and would like to add a tick box which adds 3% of the donated amount to the total to cover card fees (I want to make it optional for the donor)

I keep thinking this should be simple but I'm missing the trigger
Thanks
Last Edit: 1 month 2 weeks ago by samier.
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 2 weeks ago #43861

  • samier
  • samier's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
I have a partial solution. I created an extra donation field called threepercent then created a calculation with that as the result using

(({Amount:value} * 1.03) - {Amount:value})*10

then I hid the field using css
and now i have 3 percent added to my total. not ideal as I don't want to make it mandatory - I still want a tick box to make it optional
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 2 weeks ago #43862

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 245
  • Thank you received: 64
Simple answer would perhaps be to use conditional fields. Try this, create two dropdowns 'stuff' and 'stuff1' where stuff contains values and items like 0|-Select Option-[c], 10|item 1, 15|item 2 etc and stuff1 contains the same + 3% so 10.30|item1. Create a checkbox, lets call it add_donation containing an item ' yes add 3%. Then create two conditions to show stuff if checkbox id not 'yes add 3%' and another to show stuff1 if checkbox is 'yes add 3%'.
The only downside is that the add_donation checkbox needs to come before the stuff fields
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 1 month 2 weeks ago by iceferret. Reason: amendment
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 1 week ago #43868

  • samier
  • samier's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
I added a checkbox with Yes already ticked (Yes|Yes[c]) and with the conditions that the 3% field is hidden when unticked and shown when ticked.
Unticking the box takes away the 3% as it should but ticking it again does not add the 3% back
what am i doing wrong?
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 1 week ago #43869

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 245
  • Thank you received: 64
Not sure, the idea works for me. As long as you have two product fields one of which is 3% more that the other and you show the +3% when the box is ticked and show the other product field when it is unticked you should be right.
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 1 day ago #43880

  • samier
  • samier's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
Thanks for your Idea - it definitely has merit but this is a donation form and I don't have control over the amounts - I still have to get the donor to have the option of adding the 3%(card fee) or the 3% amount coming out of the donation.
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 1 day ago #43881

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 245
  • Thank you received: 64
Ok here's another way that lets the user input the amount. I created 3 fields, donation (textbox), add_donation (checkbox), and total (textbox). Added a new calculation total:value=donation:value then added the code below in form properties/javascript
function updateDonationValue() {
    const donationInput = document.getElementById("donation");
    const addDonationCheckbox = document.getElementById("add_donation0");
    const totalInput = document.getElementById("total");
 
    if (donationInput && totalInput) {
        let donationValue = parseFloat(donationInput.value) || 0;
 
        if (addDonationCheckbox && addDonationCheckbox.checked) {
            totalInput.value = (donationValue * 1.03).toFixed(2); // Add 3%
        } else {
            totalInput.value = donationValue.toFixed(2); // Revert to original value
        }
    }
}

call this in the additional attributes of the checkbox with onClick="updateDonationValue();"

What you have now is a siituation where the user decides the amount and whether to add the 3% the addition of whichis shown in the total field and the originsl amount in the donation field. To get the total to your payment gateway refer to the instructions here, specifically step 3

https://www.rsjoomla.com/support/documentation/rsform-pro/custom-scripting/create-a-payment-form-using-the-form-calculations-feature.html
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 1 day ago #43882

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 245
  • Thank you received: 64
Following on it occured that the user may go back and change the amount so we need to allow for that so I added a second function in properties/javascript
function uncheckDonationCheckboxOnChange(donationFieldId, checkboxId) {
    // Add an event listener to the donation field
    document.getElementById(donationFieldId).addEventListener('input', function() {
        // Uncheck the checkbox when the donation field changes
        document.getElementById(checkboxId).checked = false;
    });
}
 
// Example usage:
// Call the function with your donation field and checkbox IDs in the donation fields additional attributes
// onChange="uncheckDonationCheckboxOnChange('donation', 'add_donation0');"
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Add tick box which adds 3% to total 1 month 1 day ago #43883

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 245
  • Thank you received: 64
For interest completed the donation form so I can confirm the payment methods work with the rsfp_total hidden field. Made some final modifications:

removed the condition total:value=donation:value to prevent javascript functions being overridden
replaced previous function that unchecked the add 3% checkbox with the following function for a more seamless user experience which updates the total depending the selected/unselected state of the checkbox
function handleDonationChange(donationFieldId, checkboxId, totalFieldId) {
    let donationField = document.getElementById(donationFieldId);
    let checkbox = document.getElementById(checkboxId);
    let totalField = document.getElementById(totalFieldId);
 
    function updateTotal() {
        let donationAmount = parseFloat(donationField.value) || 0;
        let totalAmount = checkbox.checked ? donationAmount * 1.03 : donationAmount;
 
        // Ensure total is always two decimal places
        let formattedTotal = totalAmount.toFixed(2);
 
        // Update text-based elements and input fields
        if (totalField.tagName === "INPUT") {
            totalField.value = formattedTotal; // If total is an input field
        } else {
            totalField.textContent = formattedTotal; // If total is a span, div, etc.
        }
    }
 
    // Update total on donation input change
    donationField.addEventListener('input', updateTotal);
 
    // Format donation input when user clicks away (on blur)
    donationField.addEventListener('blur', function () {
        let value = donationField.value.trim();
        donationField.value = value === "" || isNaN(value) ? "0.00" : parseFloat(value).toFixed(2);
        updateTotal();
    });
 
    // Update total when checkbox is toggled
    checkbox.addEventListener('change', updateTotal);
 
    // Initialize total on page load (ensures correct value if form is prefilled)
    updateTotal();
}
 
// Example usage:
// Call the function with donation field, checkbox ID, and totalID  in the donation fields additional attributes
// onChange="handleDonationChange('donation', 'add_donation0', 'total');"
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 4 weeks 5 hours ago by iceferret.
The administrator has disabled public write access.
The following user(s) said Thank You: gregs
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!