0 Replies Latest reply on Oct 1, 2007 11:23 AM by tapping

    javascript calculation not working

    tapping
      I cannot get the following Javascript calculation to work. Could someone give me an idea of what the problem might be? The code is below:

      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
      " http://www.w3.org/TR/html4/strict.dtd">

      <head>
      <title>Patient Account Calculator</title>
      <SCRIPT LANGUAGE="JavaScript" type="text/javascript">
      /*Parse number to currency format:
      By JavaScript Kit (www.javascriptkit.com)
      Over 200+ free scripts here!
      */

      //Remove the $ sign if you wish the parse number to NOT include it
      var prefix="$"
      var wd
      function parseelement(thisone){
      if (thisone.value.charAt(0)=="$")
      return
      wd="w"
      var tempnum=thisone.value
      for (i=0;i<tempnum.length;i++){
      if (tempnum.charAt(i)=="."){
      wd="d"
      break
      }
      }
      if (wd=="w")
      thisone.value=tempnum+".00"
      else{
      if (tempnum.charAt(tempnum.length-2)=="."){
      thisone.value=tempnum+"0"
      }
      else{
      tempnum=Math.round(tempnum*100)/100
      thisone.value=tempnum
      }
      }
      }

      function calculate(){

      var cost = document.calculate.costoftreatment.value;
      var inspayment = document.calculate.insurancepayment.value;
      var dwnpayment = document.calculate.downpayment.value;

      var total = cost + inspayment;
      document.calculate.amounttobefinanced.value = total;

      }


      </script>



      <style type="text/css">
      <!--
      table {
      background-attachment: fixed;
      background-color: #CCCCCC;
      background-repeat: repeat;
      background-position: center center;
      }
      .style3 {font-size: 18px}
      .style4 {font-size: 24px; }
      .style5 {text-align:right;}
      -->
      </style>
      </head>

      <body>
      <p> </p>
      <p> </p>
      <div align="right"></div>


      <table width="43%" border="0" align="center" bgcolor="#CCCCCC">
      <tr>
      <td colspan="2"><div align="center"><img src="file:///C|/Development Folders/DGA WEB/images/Buttons/CarepayMakeQualityCareAffordable.jpg" alt="DGA CarePay / Make Quality Care Affordable" width="360" height="84" align="middle"></div></td>
      </tr>
      <tr>
      <td height="45" colspan="2" ><div align="center" class="style4">
      <p>Patient Account Calculator </p>
      </div></td>
      </tr>

      <tr>
      <td ><div align="right"><span class="style3">Cost of Treatment </span></div></td>
      <td >
      <form name = "calculate" >
      <div align="center"> <input type="text" NAME="costoftreatment" id="costoftreatment" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onChange="calculate();" ></div>
      </td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Insurance Estimate</span> </div></td>
      <td >
      <div align="center"> <input name="insurancepayment" type="text" id="insurancepayment" onchange="calculate();" ></div>
      </td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Down Payment </span></div></td>
      <td><div align="center">
      <input name="downpayment" type="text" id="downpayment" onchange="calculate();" >
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Amount to be Financed </span></div></td>
      <td><div align="center">
      <input name="amounttobefinanced" type="text" id="amounttobefinanced" onChange="calculate();" >
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Number of Payments </span></div></td>
      <td><div align="center">
      <input name="numberofpayments" type="text" id="numberofpayments" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onBlur = "parseelement(this);">
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Monthly Paymen</span>t </div></td>
      <td><div align="center">
      <input name="monthlypayment" type="text" id="monthlypayment" onchange="calculate();" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onBlur = "parseelement(this);">
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Interest Rate </span></div></td>
      <td><div align="center">
      <input name="interestrate" type="text" id="interestrate" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onBlur = "parseelement(this);">
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Total Interest Paid </span></div></td>
      <td><div align="center">
      <input name="totalinterestpaid" type="text" id="totalinterestpaid" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onBlur = "parseelement(this);">
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Total of Payments </span></div></td>
      <td><div align="center">
      <input name="totalpayments" type="text" id="totalpayments" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onBlur = "parseelement(this);">
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">Current Date </span></div></td>
      <td><div align="center">
      <input name="currentdate" type="text" id="currentdate" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onBlur = "parseelement(this);">
      </div></td>
      </tr>
      <tr>
      <td><div align="right"><span class="style3">First Payment Date </span></div></td>
      <td><div align="center">
      <input name="firstpaymentdate" type="text" id="firstpaymentdate" onKeyPress="if (event.keyCode != 46 && event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;" onBlur = "parseelement(this);">
      </div></td>
      </tr>
      <tr>
      <td>