PDA

View Full Version : Calculator working out percentages



jelly46
08-22-2013, 04:49 PM
Hello

If you go to this page https://www.barnardos.org.uk/donate/cashdonation_iframe.htm?customDonation=1.00&ref=131021&source=b&don_amount=1.00&submitButton=Single+Donation
and enter a donation amount and then click on the yes box you will see the percentage of the gift aid is worked out.

Can anyone help with a JS way to do this please?

jscheuer1
08-22-2013, 06:28 PM
document.getElementById('giftAid_IncomeAgreement').onclick = function(){ //the checkbox
if(this.checked){
var base = document.getElementById('don_amount').value, //the input with the amount's value
added = base * 0.25,
total = +base + added;
total = total.toFixed(2); //pad/crop to 2 decimal places
document.getElementById('giftAidMessage').innerHTML = 'Total amount with Gift Aid ' + total; //a span after the input
} else {
document.getElementById('giftAidMessage').innerHTML = ''; //that same span
}
}

jelly46
08-23-2013, 04:27 PM
Thanks this works now, solved