ok i have a calculator the shows results and does the math via javascript
this is the html
this is the java
For some reason i am not getting results for the calculations
this is the html
<h3>Calculate Your Debt-to-Income Ratio</h3>
<p>Comparing your earnings against your spending , also known as a
debt-to-income ratio, is one of the most popular approaches for evaluating if you have too much debt. Lenders, for years, have looked at debt-to-income ratios to get a better grasp on a person's current financial picture to determine credit-worthiness.</p>
<p>Use this calculator to calculate your debt-to-income ratio.</p>
<form name="debt_calc">
<table border=0 cellpadding=5 cellspacing=0>
<tr>
<td>Monthly mortgage or rent</td>
<td><input type="text" name="mortgage" size="10"></td>
</tr>
<tr>
<td>Minimum monthly credit card payments</td>
<td><input type="text" name="card" size="10"><br></td>
</tr>
<tr>
<td>Monthly car loan payments</td>
<td><input type="text" name="car" size="10"><br></td>
</tr>
<tr>
<td>Other loan obligations</td>
<td><input type="text" name="other" size="10"><br></td>
</tr>
<tr>
<td><b>Monthly Debt Payments</b></td>
<td><input type="text" name="debt" size="10" style="background-color:lightsteelblue;color:red;"><br></td>
<td><input type="button" name="button_income" size="1" value="Calculate Debt" onclick="calculateDebt()" style="width:140px;"></td>
</tr>
<tr>
<td>Annual gross salary</td>
<td><input type="text" name="salary" size="10"><br></td>
</tr>
<tr>
<td>Bonuses and overtime</td>
<td><input type="text" name="bonus" size="10"><br></td>
</tr>
<tr>
<td>Other income</td>
<td><input type="text" name="income" size="10"><br></td>
</tr>
<tr>
<td>Alimony received</td>
<td><input type="text" name="alimony" size="10"><br></td>
</tr>
<tr>
<td><b>Monthly Income</b></td>
<td><input type="text" name="income_total" size="10" style="background-color:lightsteelblue;"><br></td>
<td><input type="button" name="button_debt" size="1" value="Calculate Income" onclick="calculateIncome()" style="width:140px;"></td>
</tr>
<tr>
<td><b>Debt ÷ Income = </b></td>
<td><input type="text" name="ratio" size="10" style="background-color:lightsteelblue;"></td>
<td><input type="button" name="button_radio" size="20" value="Calculate Ratio" onclick="calculateRatio()" style="width:140px;"></td>
</tr>
<tr><td colspan=2 align=center><input type="reset" value="Erase Form"></td></tr>
</table>
</form>
<p>Now that you have calculated your debt-to-income ratio, understanding what it means to you is the next step. </p>
<ul>
<li> 36% or less: This is an ideal debt load to carry for most people. Showing that you can control your spending in relation to your income is what lenders are looking for when evaluating if you are credit-worthy. </li>
<br><br>
<li> 37% to 42%: Your debts still may seem manageable, but start paying them down before they begin to spiral out of control. At this level, credit cards still may be easy to obtain, but acquiring loans may be more difficult. </li>
<br><br>
<li> 43% to 49%: Your debt ratio is high and financial difficulties may be looming unless you take immediate action.</li>
<br><br>
<li> 50% or more: Seek professional help to make plans for drastically reducing your debt before it becomes a real problem. </li>
</ul>
<p>If you're concerned about your credit management, ask someone at your credit union for guidance or for referral to a credit counseling agency.</p>
<p class="byline"> </p>
</td>
this is the java
String.prototype.clearNonfloat = function () {
return this.replace(/[^\.\d]/g, '');
}
function calculateDebt() {
var mortgage = new Number(document.debt_calc.mortgage.value.clearNonfloat()) + 0;
var card = new Number(document.debt_calc.card.value.clearNonfloat()) + 0;
var car = new Number(document.debt_calc.car.value.clearNonfloat()) + 0;
var other = new Number(document.debt_calc.other.value.clearNonfloat()) + 0;
var debt_total = mortgage + card + car + other;
if(isNaN(debt_total))
{
alert("All entries must be numbers");
document.debt_calc.debt.value = "";
}
else
{
document.debt_calc.debt.value = debt_total + 0;
}
}
function calculateIncome() {
var salary = new Number(document.debt_calc.salary.value.clearNonfloat()) + 0;
var bonus = new Number(document.debt_calc.bonus.value.clearNonfloat()) + 0;
var income = new Number(document.debt_calc.income.value.clearNonfloat()) + 0;
var alimony = new Number(document.debt_calc.alimony.value.clearNonfloat()) + 0;
var income_total = Math.round((salary + bonus + income + alimony) / 12);
if(isNaN(income_total))
{
alert("All entries must be numbers");
document.debt_calc.income_total.value = "";
}
else
{
document.debt_calc.income_total.value = income_total;
}
}
function calculateRatio() {
var debt = new Number(document.debt_calc.debt.value.clearNonfloat()) +0;
var income = new Number(document.debt_calc.income_total.value.clearNonfloat()) +0;
if (debt<1)
{
income=1
}
if(debt=="" || income=="")
{
alert("You have not completed the form");
}
else
{
var ratio = debt / income;
document.debt_calc.ratio.value = Math.round(100 * ratio) + "%";
}
}
For some reason i am not getting results for the calculations
Hi macky4546,
You have two problems here:[list]You must remove the <form . . .> and </form> tags from your form HTML. ChronoForms adds its own form tags and having two sets will stop the form from working. Your JavaScript looks for the 'document.debt_calc' but ChronoForms will rename the form to 'ChronoContact_debt_calc' so you need to make equivalent changes in your JavaScript. [/list]
Bob
You have two problems here:[list]
Bob
Hi macky4546,
You have two problems here:[list]
Bob
ok i actaully got the script from another site.
now when you say the javascript looks for 'document.debt_calc', does that mean there is a document somewhere on the server that has info in it. or do i just change that to say 'ChronoContact_debt_calc'?
And im assuming you put the java script in the form javascript section under the form code section, correct?
hi macky, you are correct with all, its iwll be document.ChronoContact_debt_calc
Regards
Max
Regards
Max
function calculateDebt() {
var mortgage = new Number(document.ChronoContact_debt_calc.mortgage.value.clearNonfloat()) + 0;
var card = new Number(document.ChronoContact_debt_calc.card.value.clearNonfloat()) + 0;
var car = new Number(document.ChronoContact_debt_calc.car.value.clearNonfloat()) + 0;
var other = new Number(document.ChronoContact_debt_calc.other.value.clearNonfloat()) + 0;
var debt_total = mortgage + card + car + other;
if(isNaN(debt_total))
{
alert("All entries must be numbers");
document.ChronoContact_debt_calc.debt.value = "";
}
else
{
document.ChronoContact_debt_calc.debt.value = debt_total + 0;
}
}
that look correct, if so, its not working😟
http://www.loanmods4free.com/index.php?option=com_chronocontact&chronoformname=Calculator
Hi macky4546,
Ah. That's because your form is called Calculator (not debt-calc). Sorry, the mind reading function has failed again.
So the form name to use in the JavaScript is ChronoContact_Calculator. To save you making all the changes each time you can define a JavaScript variable.
Bob
Ah. That's because your form is called Calculator (not debt-calc). Sorry, the mind reading function has failed again.
So the form name to use in the JavaScript is ChronoContact_Calculator. To save you making all the changes each time you can define a JavaScript variable.
function calculateDebt() {
var form = document.ChronoContact_Calculator;
var mortgage = new Number(form.mortgage.value.clearNonfloat()) + 0;
var card = new Number(form.card.value.clearNonfloat()) + 0;
var car = new Number(form.car.value.clearNonfloat()) + 0;
var other = new Number(form.other.value.clearNonfloat()) + 0;
var debt_total = mortgage + card + car + other;
if ( isNaN(debt_total) ) {
alert("All entries must be numbers");
form.debt.value = "";
} else {
form.debt.value = debt_total + 0;
}
NB Not tested and may need debugging!Bob
This topic is locked and no more replies can be posted.