Skip to content

Instantly share code, notes, and snippets.

@Lucent
Created June 14, 2020 22:19
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 Lucent/8f8b9397813815f121eb1925780ada7f to your computer and use it in GitHub Desktop.
Save Lucent/8f8b9397813815f121eb1925780ada7f to your computer and use it in GitHub Desktop.
Section G mortgage calculator
<html>
<head>
<title>Section G Mortgage Calculator</title>
<style type="text/css">
TH { text-align: left; font-weight: normal; border: thin solid black; }
INPUT { text-align: right; }
</style>
<script type="text/javascript">
function cents(amount) {
amount -= 0;
amount = (Math.round(amount*100))/100;
return (amount == Math.floor(amount)) ? amount + '.00' : ((amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
function calc() {
with (document.forms["sectionG"]) {
A.value = cents(preA.value * (7/15));
C.value = cents(A.value * 1 + B.value * 1);
showC.value = C.value;
showD.value = D.value;
E.value = cents((C.value * .36 < 8750) ? C.value * .36 : 8750);
showE.value = E.value;
F.value = cents((D.value < 350000) ? E.value : (450000 - D.value) / 100000 * E.value);
if (F.value < 0) F.value = 0;
document.getElementById("Ffinal").innerHTML = (F.value) ? addCommas(F.value) : "";
}
}
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1))
x1 = x1.replace(rgx, '$1' + ',' + '$2');
return x1 + x2;
}
</script>
</head>
<body>
<form name="sectionG">
<table cellspacing=7 cellpadding=3>
<col class="Box">
<tr>
<th>Total HST paid on the home: <input type="text" name="preA" size=7 onChange="calc();"> &times; 7/15 =</th>
<td>$</td>
<td><input type="text" name="A" size=8></td>
<td>A</td>
</tr>
<tr>
<th>Total GST paid on the home</th>
<td>$</td>
<td><input type="text" name="B" size=8 onChange="calc();"></td>
<td>B</td>
</tr>
<tr>
<th>Add lines A and B</th>
<td>$</td>
<td><input type="text" name="C" size=8></td>
<td>C</td>
</tr>
<tr>
<th>Purchase price or fair market value (does not include GST/HST)</th>
<td>$</td>
<td><input type="text" name="D" size=9 onChange="calc();"></td>
<td>D</td>
</tr>
<tr>
<th>C: $<input type="text" name="showC" size=7> &times; 36% (maximum $8,750)</th>
<td>$</td>
<td><input type="text" name="E" size=9></td>
<td>E</td>
</tr>
<tr>
<th>
<li>If D is $350,000 or less, enter E</li>
<b style="margin-left: 5em;">or</b>
<li>($450,000 - D: $<input type="text" name="showD" size=9>) / $100,000 &times; E: <input type="text" name="showE" size=9>
</th>
<td>$</td>
<td><input type="text" name="F" size=9></td>
<td>F</td>
</tr>
</table>
</form>
<p>Your expected rebate is $<span id="Ffinal"></span>.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment