hi all,
I am trying to do a simple form calculation using javascript.
I have a form with three fields, I want the forms third field to update as the users completes the first two fields, which it currently does. The problem I am having is that it shows Nan and infinity when entering numbers. I would like it to display '0' until both values are entered and the loan required is < Valuation. Then i would like the calc to round up with no decimals.
Please can somebody take a look
Thanks in advance people
Code:<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript"> function startCalc(){ interval = setInterval("calc()",1); } function calc(){ one = document.autoSumForm.firstBox.value; two = document.autoSumForm.secondBox.value; document.autoSumForm.thirdBox.value = ((one * 1) / (two * 1) * 100); } function stopCalc(){ clearInterval(interval); } </script> </head> <body> <div style="width: 200px; text-align: center;"> <form name="autoSumForm"> <input class="right" type=text name="firstBox" id="Loan_Required" value="0" onFocus="startCalc();" onBlur="stopCalc();"><br> / <input class="right" type=text name="secondBox" id="Valuation" value="0" onFocus="startCalc();" onBlur="stopCalc();"><br> % <input class="right" type=text name="thirdBox" id="LTV"> </form> </div> </body> </html>


Reply With Quote

Bookmarks