0

I'm following a JS tutorial and just made a mortgage calculator that works like a charm in Chrome, but it does nothing in Firefox. Can I get some help figuring this out please? Here's the whole thing:

// Formula: c = ((p * r) *  math.pow((1 + r), n)) / (math.pow((1 + r), n) - 1)

//@param p float Amount borrowed
//@param r interest as percentage
//@param n term in years

function percentToDecimal(percent) {
return (percent / 12) / 100;
}

function yearsToMonths(years) {
return years * 12;
}

function calculateMortgage(p, r, n) {
// convert this percentage to decimal:
r = percentToDecimal(r);
n = yearsToMonths(n);

var pmt = ((p * r) * Math.pow((1 + r), n)) / (Math.pow((1 + r), n) - 1);

return parseFloat(pmt.toFixed(2));

}

function postpayments(payment) {
var payments = document.getElementById("outMonthly");
payments.innerText = "$" + payment;
}

var btn = document.getElementById("btnCalculate");
btn.onclick = function () {
var cost = document.getElementById("inCost").value;
var downpayment = document.getElementById("inDown").value;
var interest = document.getElementById("inAPR").value;
var term = document.getElementById("inPeriod").value;

var amountBorrowed = cost - downpayment;

var pmt = calculateMortgage(amountBorrowed, interest, term);

postpayments(pmt);
};
Barbarah
  • 85
  • 1
  • 8

2 Answers2

2

replace payments.innerText with payments.textContent

Hemant Pawar
  • 360
  • 1
  • 3
  • 14
1

If you want to work it across all browsers, a clean solution would be to create a TextNode and attach it to the view.

function postpayments(payment) {
    var payments = document.getElementById("outMonthly");
    while (payments.firstChild!==null)
        element.removeChild(payments.firstChild); // remove all existing content
    payments.appendChild(document.createTextNode("$" + payment));
}

Check this for more details: https://stackoverflow.com/a/1359834/891092

Community
  • 1
  • 1
ZakiMak
  • 2,072
  • 2
  • 17
  • 26