JSFiddle - React, Tailwind, and code Playground
HTML
<form action="">
<div id='field_1' class="fields">
<label for='donation_field'>Your Donation</label>
<div class="dfield">
<input id='donation_field'><br />
<span class="subtext">Enter how much you are considering donating to PCBC</span>
</div>
</div>
<br /><br />
<div id='field_2' class="fields">
<label for='tax_credit_field'>PA Tax Credit</label>
<div class="dfield">
<input id='tax_credit_field' type='text' value="" readonly=true><br />
<span class="subtext">With a 2 year commitment</span>
</div>
</div>
<br /><br />
<div id='field_3' class="fields">
<label for='tax_reduction_field'>Net Federal Tax Deduction</label>
<div class="dfield">
<input id='tax_reduction_field' type='text' value="" readonly=true><br />
<span class="subtext">Based on 35% Tax Rate</span>
</div>
</div>
<br /><br />
<div id='field_4' class="fields">
<label for='cost_field'>Cost To You</label>
<div class="dfield">
<input id='cost_field' type='text' value="" readonly=true>
</div>
</div>
</form>
CSS
.fields {
width: 500px;
}
.dfield {
display: inline;
float: right;
}
.subtext {
font-size: small;
display: block;
}
input {
float: right;
margin-right: 150px;
}
JavaScript
document.getElementById('donation_field').addEventListener("keydown", function(e) {
var key = e.keyCode ? e.keyCode : e.which;
if (!([8, 9, 13, 27, 46, 110, 190].indexOf(key) !== -1 ||
(key == 65 && (e.ctrlKey || e.metaKey)) ||
(key >= 35 && key <= 40) ||
(key >= 48 && key <= 57 && !(e.shiftKey || e.altKey)) ||
(key >= 96 && key <= 105)
)) e.preventDefault();
});
$("#donation_field").on("keyup", function() {
var donation = $(this).val();
var taxCredit = donation * 0.9;
var taxReduction = donation * 0.035;
var costToYou = donation * 0.065;
$("#tax_credit_field").val("($" + taxCredit + ")");
$("#tax_reduction_field").val("($" + taxReduction.toFixed(2) + ")");
$("#cost_field").val("$" + costToYou.toFixed(2));
});