Reputation: 853
my calculator is out putting something weird with the results I have added it to jsfiddle for you guys to take a quick look at.
If I put 4000 as my principal and 1 year and I put 1% interest it repeats the same values for the principal and the interest, it also skips every other month, but if i put a interest rate of 20% it starts counting down the results of the principal and the interest correctly. Its kinda weird.
I think the problem is with the intr variable but im not quite sure how to fix it.
function totalF(){
var body = document.body;
var tbl = document.createElement('table');
tbl.setAttribute('id', 'results');
var tblBody = document.createElement('tbody');
var tndiv = document.getElementById('tdcontainer');
for (var j = 1; j < payments; j++){
var row = document.createElement('tr');
temp = round(principal);
intr = round((monthly * payments) - principal);
while(temp>0 && intr>0){
if(tndiv != null){
var cell = document.createElement('td');
var cell2 = document.createElement('td');
var cell3 = document.createElement('td');
var ndiv = round(temp);
var intr = round((monthly * payments) - principal);
var monthlyn = j;
cell.innerHTML = ndiv;
cell2.innerHTML = monthlyn;
cell3.innerHTML = intr;
row.appendChild(cell);
row.appendChild(cell2);
row.appendChild(cell3);
j++;
}
temp-=monthly;
intr-=monthly;
tblBody.appendChild(row);
}
tbl.appendChild(tblBody);
body.appendChild(tbl);
tbl.setAttribute("border", "1");
}
}
}
Upvotes: 0
Views: 162
Reputation: 318578
Timestamp: 17.04.2012 23:13:22
Error: document.loandata.payment is undefined
Source File: http://fiddle.jshell.net/_display/
Line: 86
Use document.getElementById('loandata').payment
instead. Do the same for the other form elements or even better use var form = document.getElementById('loandata');
and then form.payment
etc.
You also try to access elements in an invalid way at other places. If an element has an ID, use document.getElementById('yourId')
to access it, and not document.yourId
or document.someElement.yourId
.
Besides that, you need to add the missing quote after the semicolon:
<div id="visualization" style="width: 750px;></div>
Upvotes: 1