home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
Search
showing results for
1<html>
2<head>
3<title></title>
4
5<script type="text/javascript">
6
7 function fixVal(value,numberOfCharacters,numberOfDecimals,padCharacter) { 
8    var i, stringObject, stringLength, numberToPad;            
9
10    value = value * Math.pow(10,numberOfDecimals);                 
11    value = Math.round(value);                                   
12    stringObject = new String(value);                            
13    stringLength = stringObject.length;                          
14    while(stringLength < numberOfDecimals) {                     
15        stringObject = "0"+stringObject;                    
16        stringLength=stringLength+1;                      
17    }
18
19    if(numberOfDecimals>0) {                       
20        stringObject=stringObject.substring(0,stringLength-numberOfDecimals)+"."+
21        stringObject.substring(stringLength-numberOfDecimals,stringLength);
22    }
23
24    if (stringObject.length<numberOfCharacters && numberOfCharacters>0) {
25        numberToPad=numberOfCharacters-stringObject.length;      
26        for (i=0; i<numberToPad; i=i+1) {
27            stringObject=padCharacter+stringObject;
28        }
29    }
30
31    return stringObject;                                      
32}
33
34function buildTable() {
35
36    var amount=parseFloat(document.getElementById("loanAmt").value );
37    var numpay=parseInt(document.getElementById("monthlyPay").value );
38    var rate=parseFloat(document.getElementById("intRte").value );
39
40    rate = rate / 100;
41    var monthly = rate / 12;
42    var payment = ((amount * monthly) / (1-Math.pow((1 + monthly), - numpay)));
43    var total = payment * numpay;
44    var interest = total - amount;
45
46    var msg = "<table border='4' width='75%'>";
47    msg += "<tr>";
48    msg += "<td>Month</td>";
49    msg += "<td>Principal Paid</td>";
50    msg += "<td>Interest Paid</td>";
51    msg += "<td>Loan Balance</td>";
52    msg += "</tr>";
53
54    newPrincipal=amount;
55    var i = 1;
56    while (i <= numpay) {
57        newInterest=monthly*newPrincipal;
58        reduction=payment-newInterest;
59        newPrincipal=newPrincipal-reduction;
60
61        msg += "<tr><td align='left' bgcolor='pink'>"+i+"</td> \
62                <td align='left' bgcolor='pink'>"+fixVal(reduction,0,2,' ')+"</td> \
63                <td align='left' bgcolor='pink'>"+fixVal(newInterest,0,2,' ')+"</td> \
64                <td align='left' bgcolor='pink'>"+fixVal(newPrincipal,0,2,' ')+"</td></tr>";
65
66        i++;
67    }
68
69
70    msg += "</table>";
71
72    document.getElementById("results").innerHTML = msg;
73
74
75}
76
77
78</script>
79
80<style type="text/css">
81
82body {
83    background: black;
84    font-family: arial;
85}
86
87#contentwrap {
88    width: 700px;
89    margin: 40px auto 0px auto;
90    background: #FFFFCC;
91    text-align: center;
92    border: 6px red solid;
93    border-radius: 10px;
94    padding: 40px;
95}
96
97table {
98    border: 5px blue double;
99    background-color: #FFFFCC;
100}
101
102#header {
103    text-align: center;
104    font-size: 2.5em;
105    text-shadow: yellow 3px 3px;
106    margin-bottom: 18px;
107    color: red;
108}
109
110#button {
111    background: blue;
112    color: white;
113    cursor: pointer;
114    padding: 5px 0px 5px 0px;
115    border: 1px solid red;
116    border-radius: 25px;
117    width: 150px;
118}
119
120.contentTitles {
121    color: green;
122    font-weight: bold;
123}
124
125.style {
126    background: lightblue;
127    font-family: comic sans ms;
128    border: 6px blue double;
129    color: green;
130    font-weight: bold;
131}
132
133</style>
134
135</head>
136
137<body>
138
139<div id="contentwrap">
140
141<div id="header">Javascript Loan Calculator</div>
142
143<form>
144
145<div class="contentTitles">Enter Loan Amount<br />
146<input type="text" id="loanAmt" class="style"><p />
147
148Interest Rate (%)<br />
149<input type="text" id="intRte" class="style"><p /> 
150
151Monthly Payment Amount<br />
152<input type="text" id="monthlyPay" class="style"><p />
153
154<div style="margin-top:20px;">
155<input type="button" value="Process Data" id="button" onClick="buildTable()">
156</div>
157
158</form>
159
160<center>
161<div id="results" style="margin-top:20px;"></div>
162</center>
163
164
165</div> <!-- ends div#contentwrap -->
166
167</body>
168</html>
upvote
downvote
source
queries leading to this page