");
console.log("5. errmsg appended");
// take user directly to error message on page load
$(window)
.scrollTop($("#errorMessage").offset().top - 60)
.scrollLeft($("#errorMessage").offset().left);
console.log("6. user taken to error message location");
} else {
}
} else {
}
// change opacity of cc image based on numerical input
var ccNumber = "";
// on input of ccnumber
$("#tfa_93").keyup(function (e) {
// set first number to variable
ccNumber = $(this).val().substring(1, 0);
// based on number, change css opacity of image
if (ccNumber == "4") {
$("#visa").css("opacity", "1");
// set card type hidden field to card type name
$("#tfa_103").val("Visa");
} else if (ccNumber == "6") {
$("#discover").css("opacity", "1");
$("#tfa_103").val("Discover");
} else if (ccNumber == "3") {
$("#amex").css("opacity", "1");
$("#tfa_103").val("American Express");
} else if (ccNumber == "5") {
$("#mastercard").css("opacity", "1");
$("#tfa_103").val("MasterCard");
} else {
// set opacity to .3 if none of the above numbers were entered
$("#visa").css("opacity", ".3");
$("#discover").css("opacity", ".3");
$("#amex").css("opacity", ".3");
$("#mastercard").css("opacity", ".3");
$("#tfa_103").val("");
}
});
// hover states on Donation Amount Radio buttons, Credit Card or Paypal Radio buttons
$("#tfa_52-L, #tfa_53-L, #tfa_54-L, #tfa_55-L, #tfa_34-L, #tfa_35-L").hover(
function () {
$(this).addClass("hover");
},
function () {
$(this).removeClass("hover");
}
);
// hover states on Donation Amount Other
$("#tfa_57").hover(
function () {
$(this).addClass("hoverOther");
},
function () {
$(this).removeClass("hoverOther");
}
);
// onclick on Other element, unselect all donation amount radio buttons
$("#tfa_57").on("click", function () {
$("#tfa_52-L, #tfa_53-L, #tfa_54-L, #tfa_55-L").css({
border: "1px solid #cccccc",
"background-color": "#f3f3f3",
});
});
// onclick on specific donation amount buttons, clear out donation other box
$("#tfa_52-L, #tfa_53-L, #tfa_54-L, #tfa_55-L").on("click", function () {
$("#tfa_57").val("");
});
// add border 1px solid when selecting radio button Donation Amount
$("#tfa_52-L, #tfa_53-L, #tfa_54-L, #tfa_55-L").on("click", function () {
$("#tfa_52-L, #tfa_53-L, #tfa_54-L, #tfa_55-L").css({
border: "1px solid #cccccc",
"background-color": "#f3f3f3",
});
$(this).css({
border: "1px solid #00aeef",
"background-color": "#effbff",
});
});
// on page load, find which dollar amount value was selected or other value inputted and, add border and background color
// is there a amount other value? if so, do nothing
if ($("#tfa_57").val().length) {
// $("#tfa_57").css({
// border: "1px solid #00aeef",
// "background-color": "#effbff",
//});
} else {
// else, find amount button selected and add css to button on load
var checkedInput = $('input[name="tfa_51"]:checked');
var checkedId = checkedInput.attr("id");
console.log("Initially checked ID:", checkedId);
$("label[for=" + checkedId + "]").css({
border: "1px solid #00aeef",
"background-color": "#effbff",
});
console.log("Added css to ", checkedId);
}
//
// add border 1px solid when selecting radio button CC or Paypal
$("#tfa_34-L, #tfa_35-L").on("click", function () {
$("#tfa_34-L, #tfa_35-L").css("border", "1px solid #cccccc");
$(this).css("border", "1px solid #00aeef");
$("#tfa_34-L, #tfa_35-L").css("background-color", "#f3f3f3");
$(this).css("background-color", "#effbff");
});
// City State Lookup
// on keyup of Zip / Postal Code field
$("#tfa_14").keyup(function (e) {
var zipCode = $(this).val();
console.log(zipCode);
if (zipCode.length === 5 && $.isNumeric(zipCode)) {
// set variable equal to Country field
var checkzip = $("#tfa_17 option:selected").text();
if (checkzip == "United States") {
var requestURL = "https://zip.getziptastic.com/v2/US/" + zipCode;
$.getJSON(requestURL, null, function (data) {
var statePickListValue = "";
// Update City field
if (data.city) $("#tfa_16").val(data.city);
statePickListValue = data.state_short + " - " + data.state;
// Update State / Province Field
if (data.state_short)
$(
'.inputWrapper option:contains("' + statePickListValue + '")'
).prop("selected", true);
});
}
}
});
});
The Planetary Fund
Your support of The Planetary Fund powers our mission to explore worlds, find life, and defend Earth.
Donate