Basic Mortgage Calculator with Explicit Rules

  • Updated

Mortgage Calculator - Basic Sample with Explicit Rules

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.

This example shows how to apply rules on an explicit rule set called "Controller", rather than simply applying all auto rules.

<script src="MortgageCalculator.min.js"></script>

<script language="javascript"> function runRules() {

// make new JS object to pass to InRule

// you could also assign fields one by one 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); entity.executeRuleSet('Controller', [], function(log){

document.getElementById('montlyPayment').value = mortgage.PaymentSummary.MonthlyPayment.toFixed(2);

document.getElementById('totalCost').value = mortgage.PaymentSummary.TotalCost.toFixed(2);

});

}

</script>

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.