Skip to content

Instantly share code, notes, and snippets.

@jbaxleyiii
Created April 16, 2015 14:31
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 jbaxleyiii/fafaabd902a4bfe02a74 to your computer and use it in GitHub Desktop.
Save jbaxleyiii/fafaabd902a4bfe02a74 to your computer and use it in GitHub Desktop.
Tithe Calculator
<h2>How Much Is Your Tithe?</h2>
<p class="light text--constrained">Enter the amount you were paid before taxes or anything else was taken out of your paycheck.</p>
<form id="tithe-calc" onsubmit="return toSubmit();" class="hard" action="#" data-parsley-validate>
<p>
<label for="gross">Paycheck Gross Amount</label>
<input id="gross" type="text" placeholder="400.00" class="text" />
</p>
<button id="submit" type="submit" class="ready submit">Calculate Tithe</button>
</form>
<form id="tithe-give" class="hard visuallyhidden" onsubmit="return createTitheURL();" >
<p>
<label for="tithe">Tithe Amount</label>
<input id="tithe" type="text" onfocus="return onReset();" class="text" />
</p>
<button id="tithe-amount" class="ready submit" type="submit">Give Now</button>
</form>
<script>
function toSubmit(){
var gross = $('#gross').val().replace(/,/g, '');
var tithe = ((gross*.1)).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, "");
var isGood = !isNaN(parseInt(tithe)) && isFinite(tithe);
if(isGood == false || tithe < 0) {
onReset();
}
else {
$('#tithe-calc').addClass('visuallyhidden');
$('#tithe-give').removeClass('visuallyhidden');
$('#tithe').val(tithe);
$('#tithe-amount').text('Give $' + tithe + ' Now');
}
return false;
}
function onReset() {
$('#gross').val('');
$('#tithe-calc').removeClass('visuallyhidden');
$('#tithe-give').addClass('visuallyhidden');
$('#gross').focus();
return false;
}
function createTitheURL() {
var titheURL = "https://give.newspring.cc/?give=" + $('#tithe').val();
window.location.href = titheURL;
return false;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment