Script not accepting some values

Discussion in 'Javascript' started by Totti, Oct 18, 2008.

  1. Totti

    Totti Guest

    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)

    <title>My Loan Calculator</title>

    <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.");
    else if (document.MyForm.LastName.value == "")
    { alert("Please enter your Last Name.");
    else if (document.MyForm.income.value == "")
    {alert("Please select an income range");
    else if (document.MyForm.age.value == "")
    {alert("Please an Age range");
    else if (document.MyForm.amount.value == "")
    {alert("Please check the Amount interval for empty or invalid
    else if (document.MyForm.interest.value == "")
    {alert("Please check the Interest rate interval for empty or invalid
    else if (document.MyForm.years.value == "")
    {alert("Please select the number of years");

    { for (i=0; i<document.MyForm.marital.length; i++)
    { if (document.MyForm.marital.checked == true)
    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:
    var row2 = trows[1].cells;
    row2[2].innerHTML = 'Your Last Name is:
    var row3 = trows[2].cells;
    row3[2].innerHTML = 'Your Income Range is:
    var row4 = trows[3].cells;
    row4[2].innerHTML = 'Your Age is:
    var row8 = trows[7].cells;
    row8[2].innerHTML = 'Your Marital is:

    <!-->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:

    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);


    <form name="MyForm" method="get" >
    <table width= 75% height = 75% border="3" id="person">
    <td width = 15%>First Name:</td>
    <td width = 15%>
    <input type="text" name="FirstName" >
    <td width=70%>Your First Name is: </td>
    <td>Last name:</td>
    <input type="text" name="LastName">
    <td>Your Last Name is: </td>
    <TD>Select your annual income range :</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

    <td>Your Income Range is: </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>
    <td>Your Age is: </td>
    <TD>Amount in $ :</TD>
    <TD><input type="text" name="amount" size="15" >
    <TD>Your Monthly Payment is :</TD>

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


    <TD>Years :</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

    <TD>Your Total Interest is :</TD>
    <td>Marital Status:</td>
    <input type="radio" name="marital" value="single" > Single
    <input type="radio" name="marital" value="married" > Married
    <input type="radio" name="marital" value="divorced">
    <input type="radio" name="marital" value="Widowed"> Widowed
    <td>Your Marital is: </td>

    <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"


    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
    Totti, Oct 18, 2008
    1. Advertisements

  2. In comp.lang.javascript message <efdb6b8a-f08f-4a5f-9ab4-fb40fe52f14e@8g>, Sat, 18 Oct 2008 09:38:25, Totti <saliba.touf
    > 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"

    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.

    (c) John Stockton, nr London UK. ? IE7 FF2 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:>.
    <URL:> jscr maths, dates, sources.
    <URL:> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, Oct 18, 2008
    1. Advertisements

  3. Totti

    Totti Guest

    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.
    Totti, Oct 19, 2008
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kathy Burke
    Kathy Burke
    Nov 14, 2003
  2. cosine... zero
    cosine... zero
    Jun 9, 2004
  3. Piers Chivers
    Piers Chivers
    Mar 2, 2004
  4. Mad Bull
    Rob Meade
    Jul 20, 2006
  5. dwelden
    Neil Cerutti
    Jan 4, 2007
  6. tshad
    Scott Roberts
    Dec 7, 2007
  7. radhakrishnan

    TextBox accepting only numeric values(

    radhakrishnan, Feb 5, 2004, in forum: ASP .Net Web Controls
  8. Good Night Moon
    Rick DeNatale
    Jul 25, 2007