Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeiLL/3c0f954dee64e013b94b9662334bb97e to your computer and use it in GitHub Desktop.
Save MikeiLL/3c0f954dee64e013b94b9662334bb97e to your computer and use it in GitHub Desktop.
<script>
// Get the parameter from the Query String
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function check(id) {
document.getElementById(id).checked = true;
}
var amount = getParameterByName('donationAmount');
// Target the Donate Buttons
function getElementsByIDSubString(type, substring) {
var allNodes = document.getElementsByTagName(type), item;
var elements = [];
for (var i = 0, len = allNodes.length; i < len; i++) {
item = allNodes[i];
if (item.id && item.id.indexOf(substring) !== -1) {
elements.push(item);
}
}
return elements;
}
var donationInputs = getElementsByIDSubString("input", "giftPledgeAmount_ucGPOtherAmountRbl");
// Get this list of Labels to add "active" class.
var amountLabels = document.querySelectorAll('[onclick="rblGPOtherAmountChangedMOF(this)"]');
// TODO Abstract this
if(amount) {
if (amount == 'five') {
check(donationInputs[0].id);
amountLabels[0].classList.add('active');
} else if (amount == 'ten') {
check(donationInputs[1].id);
amountLabels[1].classList.add('active');
} else if (amount == 'fifty') {
check(donationInputs[2].id);
amountLabels[2].classList.add('active');
} else if (amount == 'one_hundred') {
check(donationInputs[3].id);
amountLabels[3].classList.add('active');
} else { // It's Other Amount
check(donationInputs[4].id);
amountLabels[4].classList.add('active');
// Target Other Text
var otherTextArea = getElementsByIDSubString("input", "giftPledgeAmount_ucGPOtherAmountTxt_")[0];
otherTextArea.style.backgroundColor = 'white';
otherTextArea.style.color = 'black';
otherTextArea.value = '0.00';
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment