Jump to content

Someone help with my javascript problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
kentona

kentona

    Newbie

  • Members
  • PipPip
  • 19 posts
Hey guys i've finished doing my code which is displayed below,


<!-- jsset2_2b.html --> 

<html> 

  <head> 

    <title>jsset2_2b.html - Calculate Loan Enhanced</title> 

    <style type="text/css"> 

      body {

             background-color: #000000;

             color: #FFFFFF;

             font-size: 30;

             text-align: center;

           }

    </style> 

    <script type="text/javascript"> 

    function calculate()

  {

  var amount, repayment, interest, total_interest, month_interest, term_loan, rate;

 

  if (document.frmcalculateloan.txtloan.value == "")

         {

            alert("Please enter your loan amount");

            document.frmcalculateloan.txtloan.focus();

         }

         else if (document.frmcalculateloan.txtloan.value != parseFloat(document.frmcalculateloan.txtloan.value))

         {

            alert("Your loan amount must be a number");

            document.frmcalculateloan.txtloan.focus();

         }

         else if (document.frmcalculateloan.txtmonthly.value == "")

         {

            alert("Please enter your monthly loan repayment");

            document.frmcalculateloan.txtmonthly.focus();

         }

         else if (document.frmcalculateloan.txtmonthly.value != parseFloat(document.frmcalculateloan.txtmonthly.value))

         {

            alert("Your monthly loan repayment must be a number");

            document.frmcalculateloan.txtmonthly.focus();

         }

         else if (document.frmcalculateloan.txtint_rate.value == "")

         {

            alert("Please enter your interest rate");

            document.frmcalculateloan.txtint_rate.focus();

         }

         else if (document.frmcalculateloan.txtint_rate.value != parseFloat(document.frmcalculateloan.txtint_rate.value))

         {

            alert("Your interest rate must be a number");

            document.frmcalculateloan.txtint_rate.focus();

         }

 

  term_loan = 0;

  total_interest = 0;

  amount = parseFloat(document.frmcalculateloan.txtloan.value);

  repayment = parseFloat(document.frmcalculateloan.txtmonthly.value);

  rate = parseFloat(document.frmcalculateloan.txtint_rate.value);

 

  if (repayment < rate)

  {}

 

  else

  {

  while (amount > 0)

  {

 

  if (repayment < amount)

  {  

	amount = amount - repayment; 	  

	month_interest = (amount * (rate / 100) / 12);			 

	total_interest = total_interest + month_interest; 

	amount = amount + month_interest;			 

  }

  else 

  {

	amount = 0;

  }

 

	term_loan = term_loan + 1;

  } 

				

	document.frmcalculateloan.readonly_term.value = parseInt(term_loan/12) + " years and " + (term_loan % 12) + "  months";

	document.frmcalculateloan.readonly_total_interest.value = "$" + total_interest.toFixed(2);

  }

  }	

 

    function clean()

       {

         //alert("in clean");

         document.frmcalculateloan.txtloan.value = "";

		 document.frmcalculateloan.txtmonthly.value = "";

                 document.frmcalculateloan.txtint_rate.value = "";

         document.frmcalculateloan.txtloan.value = "";

         document.frmcalculateloan.readonly_term.value = "";

         document.frmcalculateloan.readonly_total_interest.value = "";

         document.frmcalculateloan.txtloan.focus();

		 document.frmcalculateloan.txtmonthly.focus();

         document.frmcalculateloan.txtloan.focus();

                 document.frmcalculateloan.txtLoanAmount.focus();

       }

 

    </script> 

    </head> 

    <body onload="window.document.frmcalculateloan.txtloan.focus()"> 

 

  <h1>Jsset2_2b - Calculate Loan Enhanced</h1> 

  <form name="frmcalculateloan"> 

  Enter the Loan Amount : $<input type="text" name="txtloan"  class="txtbox" /><br /><br /> 

  Enter the Monthly Loan Repayment : $<input type="text" name="txtmonthly"  class="txtbox" /><br /><br /> 

  Enter the Interest Rate : <input type="text" name="txtint_rate"  class="txtbox" />   %

  <br /><br /><br /> 

 

  <hr> 

  Term Of Loan: <input type="text" name="readonly_term" id="readonly_term"  disabled="READONLY" class="READONLY" /> 

  <br /><br /> 

  Total Interest Paid: <input type="text" name="readonly_total_interest" id="readonly_total_interest"  disabled="READONLY" class="disabled" /> 

  </form> 

  <br /> <br /> 

  <input type="button" name="cmdcalculate" value="Calculate term of loan and total interest" onclick="calculate()" /> 

     

 

  <input type="button" name="cmdClear" value="Reset" onClick="clean()"> 

    

   </body> 

  </html> 


Everything works fine except i want it so if the user clicks the "calculate term of loan and total interest" button it doesn't display anything in the disabled textboxes. How would i do this? I've been stuck for hours.:P

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Unfortunately it all works with me, tested in Chrome and IE.

#3
ethikz

ethikz

    Programmer

  • Members
  • PipPipPipPip
  • 112 posts
works fine in Firefox