Introduction | Demonstration Calculator | Source Code
This calculator takes the number of years you smoked, average number of cigarettes you smoked a day, and the current price for a pack of cigarettes and delivers a few figures:
The results can be pretty surprising. I smoked around 3/4 of a pack a day for 23 years. That turned out to be over 126,000 cigarettes, costing more than $37,000 and with tobacco weighing in at over 188 pounds. I smoked a grown man’s weight in tobacco.
Introduction | Demonstration Calculator | Source Code
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.
<script type="text/javascript">
function calcSmokes(){
// GET VALUES FROM FORM, SET VALUE TO ONE IF THE VALUE IN THE FORM IS NOT A NUMBER
var years = (isNaN(document.wcbubba.years.value)) ? 1 : document.wcbubba.years.value;
var smokes = (isNaN(document.wcbubba.smokes.value)) ? 1 : document.wcbubba.smokes.value;
var price = (isNaN(document.wcbubba.price.value)) ? 1 : document.wcbubba.price.value;
// DO CALCULATION OF NUMBER OF CIGARETTES SMOKED ROUNDED TO WHOLE NUMBER
var smoked = parseInt(years * 365.25 * smokes);
// CALCULATE TODAY'S VALUE OF ALL CIGS ROUNDED TO TWO DECIMAL PLACES
var expense = parseInt(((smoked/20) * price) *100) / 100;
// CALCULATE WEIGHT OF TOBACCO IN GRAMS AND POUNDS TO TWO DECIMAL PLACES
var weight = parseInt((smoked * 0.68) *100) / 100;
var pounds = parseInt(((weight/1000) * 2.204) * 100) / 100;
var expout = 'You smoked approximately ' + smoked + ' cigarettes.<br>At current prices, that would cost $' + expense + '.<br>And the weight of the tobacco in all those cigarettes was ' + pounds + ' pounds (' + weight +' grams).';
document.getElementById('totals').innerHTML = expout;
}
</script>
<form name="wcbubba" action="javascript:void();">
Number of years you smoked:<br>
<input type="text" size="5" name="years"><br><br>
Average number of cigarettes you smoked each day:<br>
<input type="text" size="5" name="smokes"><br><br>
Average price for a pack of cigarettes in your area (in dollars)<br>
<input type="text" size="5" name="price"><br><br>
<input type="submit" value="Show My Totals" onclick="calcSmokes()"></form><br>
<div id="totals"></div>
Introduction | Demonstration Calculator | Source Code
This calculator uses the same mathematical functions as our Simple Auto Loan Calculator, but iterates through each payment, calculating the interest and principal amounts for each payment as you pay off the loan.
Introduction | Demonstration Calculator | Source Code
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.
<script type="text/javascript">
var amortsub = false;
function calcLoan() {
var formvals = getFormVal();
var years = formvals[0];
var months = years;
var loan = formvals[2];
var apr = formvals[1];
var mpr = apr / 1200;
var nfactor = 0 - months;
var mofactor = Math.pow((1 + mpr), nfactor);
var bofactor = 1 - mofactor;
var tofactor = mpr / bofactor;
var payment = loan * tofactor;
var reducto = Math.round(payment*100)/100;
document.wcbubba.payment.value = "$"+reducto;
if (amortsub) showAm();
}
function showAm(){
amortsub = true;
formvals = getFormVal();
var years = formvals[0];
var months = years;
var loan = formvals[2];
var apr = formvals[1];
var mpr = apr / 1200;
var nfactor = 0 - months;
var mofactor = Math.pow((1 + mpr), nfactor);
var bofactor = 1 - mofactor;
var tofactor = mpr / bofactor;
var payment = loan * tofactor;
var reducto = Math.round(payment*100)/100;
document.wcbubba.payment.value = "$"+reducto;
// NOW WE CALCULATE THE AMORTIZATION
var intpaid = 0;
var princpaid = 0;
var factsout = "";
var inyear = 0;
var inmonth = 0;
document.getElementById('amortsub').innerHTML = '<b style="font-size:19px;">MONTHLY AMORTIZATION</b><br><br>';
for(var i=0;i<months;i++){
intpaid = Math.round((mpr * loan) *100)/100;
princpaid = Math.round((reducto - intpaid)*100)/100;
loan = Math.round((loan - princpaid)*100)/100;
inyear = parseInt(i/12);
inmonth = i - (inyear * 12);
factsout += '<b>Year ' + (inyear + 1) + ' Month ' + (inmonth +1) + ':</b><br> Principal Paid: $' + princpaid + '<br> Interest Paid: $' + intpaid + '<br> Principal Remaining: $' + loan + '<br>';
}
document.getElementById('amortsub').innerHTML += factsout;
flush();
}
function getFormVal(){
var years = parseInt(document.wcbubba.term.value);
var loan = parseInt(document.wcbubba.loan.value);
var apr = parseFloat(document.wcbubba.apr.value);
if((years <= 0)||(isNaN(years))) years = 1;
if((apr <= 0)||(isNaN(apr))) apr = 1;
if((loan <= 0)||(isNaN(loan))) loan = 1;
var mike = new Array(years,apr,loan);
return mike;
}
</script>
<form id="wcbubba" name="wcbubba" action="javascript:void();">
Loan Amount: <input type=text name="loan" size=8><br>
Loan Term: <input type=text name="term" size=8> months<br>
APR Interest: <input type=text name="apr" size=8><br><ber>
<input type="submit" value="Calculate Payment" onClick="calcLoan();"> <b>Payment:</b> <input type=text name = "payment" size=9><br>
<input type="submit" value="Show Amortization" onClick="showAm();">
</form><br><br>
<div id="amortsub">
</div>
Introduction | Demonstration Calculator | Source Code
This calculator uses the same mathematical functions as our Simple Mortgage Payment Calculator, but creates a loop, going through all the months and calculating the interest to principal ratios for each payment as you pay down the principal each month.
The amortization display is very simple. The output for each month is generated by one line of code…
factsout += '<b>Year ' + (inyear + 1) + ' Month ' + (inmonth +1) + ':</b><br> Principal Paid: $' + princpaid + '<br> Interest Paid: $' + intpaid + '<br> Principal Remaining: $' + loan + '<br>';
If you’re familiar with HTML and just have a basic knowledge of JavaScript, you can edit that to add all sorts of formatting goodness to your output.
Introduction | Demonstration Calculator | Source Code
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.
<script type="text/javascript">
var amortsub = false;
function calcLoan() {
var formvals = getFormVal();
var years = formvals[0];
var months = years * 12;
var loan = formvals[2];
var apr = formvals[1];
var mpr = apr / 1200;
var nfactor = 0 - months;
var mofactor = Math.pow((1 + mpr), nfactor);
var bofactor = 1 - mofactor;
var tofactor = mpr / bofactor;
var payment = loan * tofactor;
var reducto = Math.round(payment*100)/100;
document.wcbubba.payment.value = "$"+reducto;
if (amortsub) showAm();
}
function showAm(){
amortsub = true;
formvals = getFormVal();
var years = formvals[0];
var months = years * 12;
var loan = formvals[2];
var apr = formvals[1];
var mpr = apr / 1200;
var nfactor = 0 - months;
var mofactor = Math.pow((1 + mpr), nfactor);
var bofactor = 1 - mofactor;
var tofactor = mpr / bofactor;
var payment = loan * tofactor;
var reducto = Math.round(payment*100)/100;
document.wcbubba.payment.value = "$"+reducto;
// NOW WE CALCULATE THE AMORTIZATION
var intpaid = 0;
var princpaid = 0;
var factsout = "";
var inyear = 0;
var inmonth = 0;
document.getElementById('amortsub').innerHTML = '<b style="font-size:19px;">MONTHLY AMORTIZATION</b><br><br>';
for(var i=0;i<months;i++){
intpaid = Math.round((mpr * loan) *100)/100;
princpaid = Math.round((reducto - intpaid)*100)/100;
loan = Math.round((loan - princpaid)*100)/100;
inyear = parseInt(i/12);
inmonth = i - (inyear * 12);
factsout += '<b>Year ' + (inyear + 1) + ' Month ' + (inmonth +1) + ':</b><br> Principal Paid: $' + princpaid + '<br> Interest Paid: $' + intpaid + '<br> Principal Remaining: $' + loan + '<br>';
}
document.getElementById('amortsub').innerHTML += factsout;
flush();
}
function getFormVal(){
var years = parseInt(document.wcbubba.term.value);
var loan = parseInt(document.wcbubba.loan.value);
var apr = parseFloat(document.wcbubba.apr.value);
if((years <= 0)||(isNaN(years))) years = 1;
if((apr <= 0)||(isNaN(apr))) apr = 1;
if((loan <= 0)||(isNaN(loan))) loan = 1;
var mike = new Array(years,apr,loan);
return mike;
}
</script>
<form id="wcbubba" name="wcbubba" action="javascript:void();">
Loan Amount: <input type=text name="loan" size=8><br>
Loan Term: <input type=text name="term" size=8> years<br>
APR Interest: <input type=text name="apr" size=8><br><ber>
<input type="submit" value="Calculate Payment" onClick="calcLoan();"> <b>Payment:</b> <input type=text name = "payment" size=9><br>
<input type="submit" value="Show Amortization" onClick="showAm();">
</form><br><br>
<div id="amortsub">
</div>
Introduction | Demonstration Calculator | Source Code
Body Mass Index (BMI) is a general indicator of whether or not you are maintaining a healthy weight based on the ratio of your weight to your height. It’s an imperfect scale as it doesnt account for differences in body types. For example, a 5 foot 9 inch bodybuilder who weighs 215 pounds and has a 6% body fat would be labeled obese. And there is already a new scale just for people from Southeast Asia where the ranges are lowered.
While it can be a good indicator of the healthiness of your weight if you fall within certain statistical norms that were used to develop it, it should be taken with a significant grain of salt and should not be used as a substitute for a professional evaluation of your health by a doctor.
Introduction | Demonstration Calculator | Source Code
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.
<script type="text/javascript">
function calcBMI(){
// Get Variables and validate to make sure they're numbers,
// setting them to a value of 1 if they're not.
var weight = (isNaN(document.wcbubba.weight.value)) ? 1 : document.wcbubba.weight.value;
if (weight == 0) alert("Results will be inaccurate. Weight is not a valid number.");
var height = (isNaN(document.wcbubba.height.value)) ? 1 : document.wcbubba.height.value;
if (height == 0) alert("Results will be inaccurate. Height is not a valid number.");
// set multipliers based on whether metric or English units were selected
var wmult = (document.wcbubba.units.value == "pounds") ? 2.204 : 1;
// Turns inches/centimeters into meters
var hmult = (document.wcbubba.hunits.value == "inches") ? .0254 : .01;
// Do the calculation (weight in kg divided by the height in meters
// times itself). The multiplication by 10 and then division by ten
// work in conjunction with Math.round() to round the value to one
// decimal place of precision.
var BMI = Math.round(((weight / wmult)/((height * hmult)*(height * hmult))) *10)/10;
// get the analysis - note this is for general purpose, there is a separate scale for
// Southeast Asian people and there may be more variants on the way
var result = "";
if(BMI < 16.5) result = "severely underweight";
else if((BMI >=16.5)&&(BMI<=18.49)) result = "underweight";
else if((BMI >=18.5)&&(BMI<=25)) result = "normal";
else if((BMI >=25.01)&&(BMI<=30)) result = "overweight";
else if((BMI >=30.01)&&(BMI<=35)) result = "obese";
else if((BMI >=35.01)&&(BMI<=40)) result = "clinically obese";
else result = "morbidly obese";
document.getElementById('results').innerHTML = "Your Body Mass Index (BMI) is: " + BMI + ".<br><br>This would be considered " + result + ".";
}
</script>
<form name="wcbubba" id="wcbubba" action="javascript:void()">
Weight:<br> <input type=text name="weight" size="6"> <select name="units"><option value="pounds">pounds<option value="kilos">kg</select><br><br>
Height:<br> <input type=text name="height" size="6"> <select name="hunits"><option value="inches">inches<option value="cm">cm</select><br><br>
<input type="submit" value="Calculate My BMI" onClick="calcBMI();"></form><br>
<div id="results" style="border:1px solid #000;padding:4px;font-size:15px;font-weight:bold;width:400px;">
Your BMI is:<br><br>
</div>
Introduction | Demonstration Calculator | Source Code
How many calories do you need to eat in a day to maintain your current weight? That’s different for each and every individual. The only way to get a highly accurate number is a lab test where you sleep at the lab and they take measurements right as you wake up from 8 hours of sleep and at least 12 hours of fasting.
This calculator uses the formula for Basal Metabolic Rate (BMR) devised by doctors at the University of Nevada Medical School and published in the American Journal of Clinical Nutrition in 1990, then uses the Harris Benedict activity multiplier to determine your estimated daily caloric burn off.
Remember that the Basal Metabolic Rate is how many calories you’d need to maintain your body weight if all you did all day was lay in bed and your only activity was eating. Just sitting up and typing a a few hours a day, walking from the couch to your car, from the car to your office, etc. boosts your daily needs up by 20%. If you lead a lifestyle where you have high levels of exertion every day, it can nearly double your calorie needs.
Just fill out the fields in the form below and click “calculate my calorie needs” to get your BMR and your daily calorie needs.
Introduction | Demonstration Calculator | Source Code
Your Average Daily Calorie Need is:
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.
<script type="text/javascript">
function calcNeeds(){
var weight = (isNaN(document.wcbubba.weight.value)) ? 0 : document.wcbubba.weight.value;
if (weight == 0) alert("Results will be inaccurate. Weight is not a valid number.");
var height = (isNaN(document.wcbubba.height.value)) ? 0 : document.wcbubba.height.value;
if (height == 0) alert("Results will be inaccurate. Height is not a valid number.");
var age = (isNaN(document.wcbubba.height.value)) ? 0 : document.wcbubba.age.value;
if (age == 0) alert("Results will be inaccurate. Age is not a valid number.");
var activity = (isNaN(document.wcbubba.activity.value)) ? 0 : document.wcbubba.activity.value;
var wmult = (document.wcbubba.units.value == "pounds") ? 2.204 : 1;
var hmult = (document.wcbubba.hunits.value == "inches") ? 2.54 : 1;
var genvar = (document.wcbubba.gender.value == "male") ? 5 : -161;
var BMR = Math.round((((weight / wmult) * 9.99) + ((height * hmult) * 6.25) - (age * 4.92) + genvar) * 1);
var calburn = Math.round((((weight / wmult) * 9.99) + ((height * hmult) * 6.25) - (age * 4.92) + genvar) * activity);
document.getElementById('results').innerHTML = "Your Basal Metabolic Rate is: " + BMR + " calories.<br><br>Your Average Daily Calorie Need Is: " + calburn + " calories";
}
</script>
<form name="wcbubba" id="wcbubba" action="javascript:void()">
Weight:<br> <input type=text name="weight" size="6"> <select name="units"><option value="pounds">pounds<option value="kilos">kg</select><br><br>
Age:<br><input type=text name="age" size="6"> (in years)<br><br>
Gender:<br><select name="gender"><option value="male">male<option value="female">female</select><br><br>
Height:<br> <input type=text name="height" size="6"> <select name="hunits"><option value="inches">inches<option value="cm">cm</select><br><br>
Activity Level:<br> <select name="activity">
<option value="1.2">Little or no exercise and desk job
<option value="1.375">Lightly strenuous exercise or casual sports 1-3 days a week
<option value="1.55">Moderately strenuous exercise or somewhat aggressive sports 3-5 days a week
<option value="1.725">Strenuous exercise or aggressive sports 6-7 days a week
<option value="1.9">Strenuous daily exercise or aggressive sports and a physically active job</select><br><br>
<input type="submit" value="Calculate My Calorie Needs" onClick="calcNeeds();"></form><br>
<div id="results" style="border:1px solid #000;padding:4px;font-size:15px;font-weight:bold;width:400px;">
Your Basal Metabolic Rate is:<br><br>
Your Average Daily Calorie Need is:
</div>
Introduction | Demonstration Calculator | Source Code
Enter your name and the name of the person you want to be matched with into the appropriate boxes in the calculator, then click “Calculate Our Compatibility”. A client-side JavaScript uses AJAX to query Google for the number of search results that come up for each name at Google. It then uses those numbers to determine a compatibility score.
Introduction | Demonstration Calculator | Source Code
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Download popucalc.zip. In it you will find the three graphics, PHP script for querying Google via their RESTful search API, an HTML file with the AJAX JavaScript and the search form, plus a README file with further instructions on getting it running.
Here are the two source files if you’d like to examine them.
JavaScript & HTML source code
<script type="text/javascript">
var firstval = "";
var secondval = "";
var firstdone = false;
var seconddone = false;
var offset=3;
function popucalc(){
document.getElementById('calcresults').innerHTML = '<b>Calculating</b><br /><img src="/images/pleasewait.gif">';
var firstname = escape(document.popcalc.firstname.value);
var getURL = 'popucalc.php?SP=' + firstname;
parseName(getURL,'first name');
var secondname = escape(document.popcalc.secondname.value);
getURL = 'popucalc.php?SP=' + secondname;
parseName(getURL,'second name');
}
function parseName(getURL,nameID)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
//this is the part that processes the incoming data
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var myresults = xmlHttp.responseText;
parseResults(myresults,nameID);
}
}
//This is the part that sends it
xmlHttp.open("get",getURL,true);
xmlHttp.send(null);
}
function parseResults(result,nameID){
if(nameID == 'first name') {
firstval = (isNaN(parseInt(result))) ? 0 : parseInt(result);
firstdone = true;
} else if (nameID == "second name"){
secondval = (isNaN(parseInt(result))) ? 0 : parseInt(result);
seconddone = true;
}
if((firstdone)&&(seconddone)) showresults();
}
function showresults(){
var topper;
var bottomer;
firstdone=false;
seconddone=false;
if(firstval > secondval){
bottomer = firstval;
topper = secondval;
} else {
topper = firstval;
bottomer = secondval;
}
var popindex;
if((topper == 0)||(bottomer==0)){
popindex = 0;
} else {
var popindex = (topper/bottomer);
popindex = Math.round(popindex*1000)/1000
}
var popcover = Math.round(200 - ((popindex * 190) + 10));
var popamt = Math.round(popindex * 1000)/10;
var resultspot = document.getElementById('calcresults');
var resout = '<b>Matched: ' + popamt + '% </b><br>' + document.popcalc.firstname.value + ' and ' + document.popcalc.secondname.value + '<br>';
resout += '<div style="width:210px;height:35px;padding:5px;border:1pt solid #222;font-size:12px;"><div style="width:100px;float:left;text-align:left">Cool</div><div style="width:100px;float:left;text-align:right">Scorching</div><br style="clear:all">';
var quoter = "'/images/pcgradient.gif'";
resout += '<div style="width:200px;height:20px;margin:0px;padding:0px; background:url('+quoter+');text-align:right;"><img src="/images/pcwhite.gif" height=20 width=' + popcover + ' style="margin:0px;padding:opx;border:none;" /></div></div><br /><br />';
resultspot.innerHTML = resout;
}
</script>
<div style="border:2px solid #222;margin:5px;padding:5px;width:350px;"><h3>GOOGLE COMPATIBILITY CALCULATOR</H3>
<form name="popcalc" action="javascript:void();">
Your Name: <input size=20 name="firstname" id="firstname" type=text> <br>
Crush's Name: <input size=20 name="secondname" id="secondname" type=text><br>
<input type="submit" value="Calculate Our Compatibility" onClick="popucalc()";>
</form>
<div id="calcresults" style="height:100px;"></div><br />
</div>
PHP source code
<?php
$searchphrase = $_REQUEST["SP"];
$searchphrase = str_replace(""","",$searchphrase);
$searchphrase = str_replace("%22","",$searchphrase);
$searchphrase=urlencode($searchphrase);
$booboo = passnum($searchphrase);
echo $booboo;
function passnum($searchphrase){
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%22" . $searchphrase . "%22";
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.mysite.com/index.html");
$body = curl_exec($ch);
curl_close($ch);
// now, process the JSON string
$json = json_decode($body, true);
// now have some fun with the results...
$sam = $json["responseData"]["cursor"]["estimatedResultCount"];
return $sam;
}
?>
Introduction | Demonstration Calculator | Source Code
This is a very simple calculator for calculating an auto loan payment. Enter in the amount of the loan, the number of months the loan is for, and the APR. Then click “Calculate Payment” to get your monthly auto loan payment.
If you change the values, click the “Calculate Payment” button again to get a new result.
Introduction | Demonstration Calculator | Source Code
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.
<script type="text/javascript">
function calcLoan() {
var formvals = getFormVal();
var months = formvals[0];
var loan = formvals[2];
var apr = formvals[1];
var mpr = apr / 1200;
var nfactor = 0 - months;
var mofactor = Math.pow((1 + mpr), nfactor);
var bofactor = 1 - mofactor;
var tofactor = mpr / bofactor;
var payment = loan * tofactor;
var reducto = Math.round(payment*100)/100;
document.wcbubba.payment.value = "$"+reducto;
if (amortsub) showAm();
}
function getFormVal(){
var years = parseInt(document.wcbubba.term.value);
var loan = parseInt(document.wcbubba.loan.value);
var apr = parseFloat(document.wcbubba.apr.value);
if((years <= 0)||(isNaN(years))) years = 1;
if((apr <= 0)||(isNaN(apr))) apr = 1;
if((loan <= 0)||(isNaN(loan))) loan = 1;
var mike = new Array(years,apr,loan);
return mike;
}
</script>
<form id="wcbubba" name="wcbubba" action="javascript:void();">
Loan Amount: <input type=text name="loan" size=8>
Loan Term: <input type=text name="term" size=8> months
APR Interest: <input type=text name="apr" size=8>
<br /><br />
<input type="submit" value="Calculate Payment" onClick="calcLoan();">
<br /><br />
<b>Payment:</b> <input type=text name = "payment" size=9><br>
</form></p>
Introduction | Demonstration Calculator | Source Code
This is a very simple calculator for calculating a mortgage payment. Enter in the amount of the loan, the number of years the loan is for, and the APR. Then click “Calculate Payment” to get your monthly mortgage payment.
If you change the values, click the “Calculate Payment” button again to get a new result.
Introduction | Demonstration Calculator | Source Code
Introduction | Demonstration Calculator | Source Code
This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.
Required Credit HTML
INSTALLATION
Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.
<script type="text/javascript">
function calcLoan() {
var formvals = getFormVal();
var years = formvals[0];
var months = years * 12;
var loan = formvals[2];
var apr = formvals[1];
var mpr = apr / 1200;
var nfactor = 0 - months;
var mofactor = Math.pow((1 + mpr), nfactor);
var bofactor = 1 - mofactor;
var tofactor = mpr / bofactor;
var payment = loan * tofactor;
var reducto = Math.round(payment*100)/100;
document.wcbubba.payment.value = "$"+reducto;
if (amortsub) showAm();
}
function getFormVal(){
var years = parseInt(document.wcbubba.term.value);
var loan = parseInt(document.wcbubba.loan.value);
var apr = parseFloat(document.wcbubba.apr.value);
if((years <= 0)||(isNaN(years))) years = 1;
if((apr <= 0)||(isNaN(apr))) apr = 1;
if((loan <= 0)||(isNaN(loan))) loan = 1;
var mike = new Array(years,apr,loan);
return mike;
}
</script>
<form id="wcbubba" name="wcbubba" action="javascript:void();">
Loan Amount: <input type=text name="loan" size=8>
Loan Term: <input type=text name="term" size=8> years
APR Interest: <input type=text name="apr" size=8>
<br /><br />
<input type="submit" value="Calculate Payment" onClick="calcLoan();">
<br /><br />
<b>Payment:</b> <input type=text name = "payment" size=9><br>
</form></p>