Script not accepting some values

T

Totti

Hi all, first of all i am not sure if it is proper to paste a code on
the news group, if it is not please forgive this time and just tell me
that it is not a proper way to solve problems!

My problem bears in a code i ve written as an excercise on javascript
that i m learning myself for the last 4 weeks or so, i am trying to
make a form that can calculate a loan, there are plenty of them on the
internet but i wanted to make one myself here is its code(i am pasting
the code so one can check it)

------------------------
<html>
<head>
<title>My Loan Calculator</title>
</head>

<body onload ="alert('Welcome to My Loan Calculator')";>
<script language="javascript">

function checkall()
{
var radio = -1;
if (document.MyForm.FirstName.value == "")
{ alert("Please enter your First Name.");
document.MyForm.FirstName.focus();
}
else if (document.MyForm.LastName.value == "")
{ alert("Please enter your Last Name.");
document.MyForm.LastName.focus();
}
else if (document.MyForm.income.value == "")
{alert("Please select an income range");
document.MyForm.income.focus();
}
else if (document.MyForm.age.value == "")
{alert("Please an Age range");
document.MyForm.age.focus();
}
else if (document.MyForm.amount.value == "")
{alert("Please check the Amount interval for empty or invalid
data");
document.MyForm.amount.focus();
}
else if (document.MyForm.interest.value == "")
{alert("Please check the Interest rate interval for empty or invalid
data");
document.MyForm.interest.focus();
}
else if (document.MyForm.years.value == "")
{alert("Please select the number of years");
document.MyForm.years.focus();
}

else
{ for (i=0; i<document.MyForm.marital.length; i++)
{ if (document.MyForm.marital.checked == true)
{radio=i;}
}
if (radio == -1)
{alert("Please select your Marital status");}
}

if (radio != -1)
{

var trows = document.getElementById('person').rows;
var row1 = trows[0].cells;
row1[2].innerHTML = 'Your First Name is:
'+document.MyForm.FirstName.value;
var row2 = trows[1].cells;
row2[2].innerHTML = 'Your Last Name is:
'+document.MyForm.LastName.value;
var row3 = trows[2].cells;
row3[2].innerHTML = 'Your Income Range is:
'+document.MyForm.income.value;
var row4 = trows[3].cells;
row4[2].innerHTML = 'Your Age is:
'+document.MyForm.age.value;
var row8 = trows[7].cells;
row8[2].innerHTML = 'Your Marital is:
'+document.MyForm.marital[radio].value;

<!-->It is Stopping here<-->

var interest1 = (document.MyForm.interest.value / 1200);
var payment = (12 * document.MyForm.years.value);
var x = (Math.pow((1 + interest1), payment));
var perMonth = ((amount * x * interest1)/(x-1));

var row5 = trows[4].cells;
row5[2].innerHTML = 'Your Monthly Payment is:
'+document.MyForm.round(perMonth).value;

var row6 = trows[5].cells;
row6[2].innerHTML = 'Your Total Interest is :
'+document.MyForm.ceil(perMonth * payment).value;

var row7 = trows[6].cells;
row7[2].innerHTML = 'You Total Payment is :
'+document.MyForm.ceil((perMonth * payment) - amount).value;



}

}

function round(x)
{
return Math.round(x*100)/100;
}

function ceil(x)
{
return Math.ceil(x);
}

</script>

<form name="MyForm" method="get" >
<table width= 75% height = 75% border="3" id="person">
<tr>
<td width = 15%>First Name:</td>
<td width = 15%>
<input type="text" name="FirstName" >
</td>
<td width=70%>Your First Name is: </td>
</tr>
<tr>
<td>Last name:</td>
<td>
<input type="text" name="LastName">
</td>
<td>Your Last Name is: </td>
</tr>
<tr>
<TD>Select your annual income range :</TD>
<TD>
<select name="income" size="5" >
<option value="0 - 10000"> 0 - 10000
<option value="10001 - 20000"> 10001 - 20000
<option value="20001 - 30000"> 20001 - 30000
<option value="30001 - 40000"> 30001 - 40000
<option value="40001 - 50000"> 40001 - 50000
<option value="50001 - 60000"> 50001 - 60000
<option value="60001 - 70000"> 60001 - 70000
<option value="70001 - 80000"> 70001 - 80000
<option value="80001 - 90000"> 80001 - 90000
<option value="90001 - 100000"> 90001 - 100000
<option value="100001 - UP"> 100001 - UP
</select>

<td>Your Income Range is: </td></TD>
</TR>
<tr>
<td>Age:</td>
<td>
<select name="age" size=2>
<option value="18-25">18-25</option>
<option value="26-35">26-35</option>
<option value="36-50">36-50</option>
<option value="51 and Older">51 and Older</option>
</select>
</td>
<td>Your Age is: </td>
</tr>
<tr>
<TD>Amount in $ :</TD>
<TD><input type="text" name="amount" size="15" >
<TD>Your Monthly Payment is :</TD>
</TD>
</TR>

<TR>
<TD>Interest in % :</TD>
<TD><input type="text" name="interest" size="15" >
<TD>Your Total Payment is :</TD>

</TD>
</TR>

<TR>
<TD>Years :</TD>
<TD>
<select name="years" size="3" >
<option value=1> 1
<option value=2> 2
<option value=3> 3
<option value=4> 4
<option value=5> 5
<option value=6> 6
<option value=7> 7
<option value=8> 8
<option value=9> 9
<option value=10> 10
<option value=11> 11
<option value=12> 12
<option value=13> 13
<option value=14> 14
<option value=15> 15
<option value=16> 16
<option value=17> 17
<option value=18> 18
<option value=19> 19
<option value=20> 20
<option value=21> 21
<option value=22> 22
<option value=23> 23
<option value=24> 24
<option value=25> 25

</select>
<TD>Your Total Interest is :</TD>
</TD>
</TR>
<tr>
<td>Marital Status:</td>
<td>
<input type="radio" name="marital" value="single" > Single
<br>
<input type="radio" name="marital" value="married" > Married
<br>
<input type="radio" name="marital" value="divorced">
Divorced
<br>
<input type="radio" name="marital" value="Widowed"> Widowed
</td>
<td>Your Marital is: </td>
</tr>
</table>
<p>

<TR>
<TD colspan="2" bgcolor = black align = center>
<input type="button" value="Compute" onClick="checkall();">
<input type=reset value="Clear Fields" name=reset >
<input type="button" value="Help"
onClick="window.location.href='help.html'">
</TD>
</TR>

</p>
</form>
</body>
</html>
-------------------------------------------------------------------------

Here is the problem, after the user enters everything she is asked to,
the script is supposed to calculate few things and print them out with
the other fields. I am sure my calculations are correct because i ve
tried calculating with simple java. therefore the problem is not in
the calculations actually it is stopping where i ve put a note, (<!--
It is Stopping here<-->
) i ve been working on it a day and a half without success i know i m
missing something but i dont know what is it. would anybody please
help me after checking the code ? what am i doing wrong . thanks in
advance
 
D

Dr J R Stockton

In comp.lang.javascript message <efdb6b8a-f08f-4a5f-9ab4-fb40fe52f14e@8g
2000hse.googlegroups.com>, Sat, 18 Oct 2008 09:38:25, Totti <saliba.touf
(e-mail address removed)> posted:
Hi all, first of all i am not sure if it is proper to paste a code on
the news group, if it is not please forgive this time and just tell me
that it is not a proper way to solve problems!

If you had read and heeded the FAQ before asking, you would have known
that; and your question might have been attended to sooner. After
fixing the errors you introduced by not doing so, just run the code in
Firefox with the error console open and you will be told exactly where
the problem is. It is not where you marked, but a little further, after
the Math.pow line. You could have discovered that by inserting "alert"
statements.

Firefox says
Error: amount is not defined
Source File: file:///C:/HOMEPAGE/$1.htm <- my copy
Line: 70

You have used document.MyForm.amount.value in validating. and
similar to read interest just after you thought it stopped; but you
have not used it to read the value from amount for calculating.

I cannot recommend using the same name for a form element and the value
taken from it; you are liable to confuse yourself.

Read FAQ 4.1 .. 4.4 (after reading the whole FAQ); you will need it.

Also, check your HTML with one of W3's testers, and correct it.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
T

Totti

Thanks a lot for pointing that out, i checked using alerts and i
solved my problem. one thing is that till this moment i wasn't using
FF and its console, therefore i havent had this knowledge, thanks for
this as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top