Basic Mortgage Calculator

  • Updated

Mortgage Calculator - Basic Sample

This sample uses JavaScript to read the data from the form, write the values into a JavaScript object and then calls the rule engine with the object. The results are then written back to the form.

<script src="MortgageCalculator.min.js"></script>
<script language="javascript">
function runRules() {
var mortgage = {};
mortgage.LoanInfo = {};
mortgage.LoanInfo.Principal = document.getElementById('loanAmount').value;
mortgage.LoanInfo.APR = document.getElementById('apr').value;
mortgage.LoanInfo.TermInYears =
document.getElementById('termInYears').value;
var session = inrule.createRuleSession();
var entity = session.createEntity('Mortgage', mortgage);
session.applyRules(function(log){
if(!log.hasErrors){
document.getElementById('montlyPayment').value =
mortgage.PaymentSummary.MonthlyPayment.toFixed(2);
document.getElementById('totalCost').value =
mortgage.PaymentSummary.TotalCost.toFixed(2);
}
else{
console.log(log.runtimeErrors.join('\n'));
}
});
}
</script>

 

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.