Created
April 16, 2015 14:31
-
-
Save jbaxleyiii/fafaabd902a4bfe02a74 to your computer and use it in GitHub Desktop.
Tithe Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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