SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Insurance Calculator
-
Jun 4, 2008, 14:20 #1
- Join Date
- Jun 2004
- Location
- Fantastic US of A
- Posts
- 124
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Insurance Calculator
I'm writing an insurance calculator which I have functioning perfectly except one value. I need the floridaForm9 variable to give me 10% of the ending value of the titleCombo variable. The code below is the full javascript along with the basic table to gather/show the data. Any help would be fantastic! I've pulled my hair out today to try and make it calculate that last value and just can't seem to get it..... I would think i could just put floridaForm9 = titleCombo *.1; but that doesn't give me anything exported.
Code:<script language="JavaScript" type="text/JavaScript"> <!-- function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> <script language="JavaScript"> <!-- This is to hide the script from old browsers. // //The Formname is formTitleCalc // function resetInputs() { } function calculateValues() { var purchPrice = conditionInput(document.formTitleCalc.purchPrice.value); var addOn = 0; var titleCombo = 0; var titleOwner = 0; var closingFee = 375; var abstractTitleSearch = 115; var counterPackageHandling = 75; var wireFee = 50; var floridaForm9 = 0; var endorseMents = 50; var imageFee = 35; var documentRetentionFee = 20; var v01 = eval(closingFee); var v02 = eval(abstractTitleSearch); var v03 = eval(floridaForm9); var v04 = eval(endorseMents); var v05 = eval(imageFee); var v06 = eval(counterPackageHandling); var v07 = eval(wireFee); var closingTotal = 0; amtBreak1 = 100000 amtBreak2 = 1000000 amtBreak3 = 5000000 amtBreak4 = 10000000 amtBreak5 = 10000000.01 premRate1 = 5.75 premRate2 = 5 premRate3 = 2.5 premRate4 = 2.25 premRate5 = 2 //Is purchPrice numeric? if (isNaN(purchPrice)) { alert("Invalid Purchase Price") document.formTitleCalc.purchPrice.value = "" document.formTitleCalc.purchPrice.focus() return (false) } if(purchPrice == 0) { alert("Please enter a value for the Purchase Price!"); document.formTitleCalc.purchPrice.focus(); return false; } addOn = eval(addOn); amtBreak1 = 100000 amtBreak2 = 1000000 amtBreak3 = 5000000 amtBreak4 = 10000000 amtBreak5 = 10000000.01 premRate1 = 5.75 premRate2 = 5 premRate3 = 2.5 premRate4 = 2.25 premRate5 = 2 titleCombo = calc1Value(purchPrice, amtBreak1, amtBreak2, amtBreak3, amtBreak4, amtBreak5, premRate1, premRate2, premRate3, premRate4, premRate5); titleCombo = titleCombo + addOn; titleCombo = roundCent(titleCombo); titlePolicy = titleCombo; document.formTitleCalc.purchPrice.value = formatDollar(purchPrice); document.formTitleCalc.titleCombo.value = formatDollar(titleCombo); //var closingTotal = v01 + v02 + v03 + titlePolicy + v04 + v05 + v06 + v07 + v08 + v09; var closingTotal = v01 + v02 + v03 + titlePolicy + v04 + v05 + v06 + v07; // document.formTitleCalc.curBal.value = formatDollar(curBal); document.formTitleCalc.closingFee.value = formatDollar(v01); document.formTitleCalc.abstractTitleSearch.value = formatDollar(v02); document.formTitleCalc.floridaForm9.value = formatDollar(v03); document.formTitleCalc.endorseMents.value = formatDollar(v04); document.formTitleCalc.imageFee.value = formatDollar(v05); document.formTitleCalc.counterPackageHandling.value = formatDollar(v06); document.formTitleCalc.wireFee.value = formatDollar(v07); document.formTitleCalc.closingTotal.value = formatDollar(closingTotal); return(true) // End of function calculateValues } function calc1Value(InsuredValue, aB1, aB2, aB3, aB4, aB5, pR1, pR2, pR3, pR4, pR5) // // Example: The charge is 3.25 per thousand for the first 200000, // 2.25 per thousand for the next 800000 to $1 million. // 1.25 per thousand for everything above that. // // var amtBreak1 = 200000 // var amtBreak2 = 1000000 // var premRate1 = 3.25 // var premRate2 = 2.25 // var premRate3 = 1.25 // In this example a 1.3 million house would be: // 3.25 * 200000 / 1000 = 650 // 2.25 * 800000 / 1000 = 1800 // 1.25 * 300000 / 1000 = 375 // Total = 2825 // // To increase 10%: // premRate1 = 3.575 // premRate2 = 2.475 // premRate3 = 1.375 //The example would give the following: // 3.575 * 200000 / 1000 = 715.00 // 2.475 * 800000 / 1000 = 1980.00 // 1.375 * 300000 / 1000 = 412.50 // Total = 3107.50 // Note that 2825 * 110% = 3107.50 // // The calculation is as follows: // Purchase // Owners Policy = 3.25 per thousand or fraction for the first $200,000 // 2.25 per thousand or fraction for $200,000.01 to and including $1 million // 1.25 per thousand or fraction for $1,000,000.01 and above // // // Premium Add-on = 0 // Gross Premium = Owners Policy + Premium Add-on // This is the place where the premium breaks: // Example: The charge is 2.25 per thousand for the first 200000 and 2 per thousand for everything above that. // var amtBreak1 = 200000 // var premRate1 = 2.25 // var premRate2 = 2 // In this example a 365000 house would be: // 2.25 * 200000 / 1000 = 450 // 2 * 165000 / 1000 = 330 // Total = 780 // // To increase 10%: // premRate1 = 2.475 // premRate2 = 2.20 // But the example would give the following: // 2.475 * 200000 / 1000 = 495 // 2.2 * 165000 / 1000 = 363 // Total = 858 // Note that 780 * 110% = 858 // // { var premRate = 0 var cumPrem = 0; var loanThou = RoundUpToThousand(InsuredValue) / 1000 var remainThou = loanThou var breakThou = RoundUpToThousand(aB1) / 1000 //breakThou = 200 if (remainThou > breakThou) { premRate = eval(pR1) cumPrem = cumPrem + premRate * breakThou; remainThou = remainThou - breakThou breakThou = RoundUpToThousand(aB2 - aB1) / 1000 premRate = eval(pR2) if (remainThou > breakThou) { cumPrem = cumPrem + premRate * breakThou; remainThou = remainThou - breakThou breakThou = RoundUpToThousand(aB3 - aB2) / 1000 premRate = eval(pR3) if (remainThou > breakThou) { cumPrem = cumPrem + premRate * breakThou; remainThou = remainThou - breakThou breakThou = RoundUpToThousand(aB4 - aB3) / 1000 premRate = eval(pR4) if (remainThou > breakThou) { cumPrem = cumPrem + premRate * breakThou; remainThou = remainThou - breakThou premRate = eval(pR5) cumPrem = cumPrem + premRate * remainThou; } else { premRate = eval(pR4) cumPrem = cumPrem + premRate * remainThou; } } else { premRate = eval(pR3) cumPrem = cumPrem + premRate * remainThou; } } else { premRate = eval(pR2) cumPrem = cumPrem + premRate * remainThou; } } else { premRate = eval(pR1) cumPrem = cumPrem + premRate * remainThou; } cumPrem = roundCent(cumPrem); result = cumPrem; return result; // End of function calculate1Value } // // Utilities // function conditionInput(passParm) { if (passParm == "") { result = 0; } else { if (passParm.indexOf("$") > -1) { passParm = passParm.substring(1); } while (passParm.indexOf(",") > -1) { tempStr = passParm; passParm = tempStr.substring(0, tempStr.indexOf(",")) + tempStr.substring(tempStr.indexOf(",") + 1); } result = passParm; } return result; } // // Round the computed value up to the next thousand. // function RoundUpToThousand(passParm) { var resultThou = Math.floor((eval(passParm) + 999.99) * .001) * 1000 return resultThou } // end of function RoundUpToThousand // // Round the computed value to 2 decimal places. // function roundCent(passParm) { var resultCent = Math.floor((eval(passParm) + .005) * 100) * .01; return resultCent; } // // Prefix a dollar sign and insert commas into the data. // This is also one of the pieces of logic that I don't feel especially good about. // function formatDollar(passParm) { var decPlaces = 2; var formattedVal = "$" + formatDecimal(passParm, decPlaces); return formattedVal } // end of function formatDollar // // function formatDecimal(passParm, passPrecision) { // // Format numeric string with decimal point and commas. // var j1 var strMtx = new Array() var resultDecimal var strMid var strFin // convert passParm to numeric, in case it is somehow alphanumeric. passParm = passParm * 1 strMid = "" + Math.round(eval(passParm) * Math.pow(10,passPrecision)) while(strMid.length <= passPrecision) { strMid = "0" + strMid; } var decPos = strMid.length - passPrecision //> return strMid.substring(0,decPos) + "." + strMid.substring(decPos, strMid.length); strFin = strMid.substring(0,decPos); j1 = Math.ceil(strFin.length / 3) - 1; while (strFin.length > 0) { strMtx[j1] = strFin.substring(strFin.length - 3, strFin.length); strFin = strFin.substring(0, strFin.length - 3); j1--; } resultDecimal = strMtx.join(",") + "." + strMid.substring(decPos, strMid.length) return resultDecimal } // end of function formatDecimal // // //--> </script> </head> <body bgcolor="#F2F1E6" text="#000000" link="#003366" vlink="#999999" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/nav/about_ON.gif','images/nav/what_ON.gif','images/nav/office_ON.gif','images/nav/online_ON.gif','images/nav/rates_ON.gif','images/nav/schedule_ON.gif','images/nav/document_ON.gif')"> <table width="96%" border="0" cellspacing="10" cellpadding="0"> <tr align="left" valign="top"> <td valign="top" align="center"> <table width="92%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="top"> <font size="3" face="Arial, Helvetica, sans-serif"><b>Title Policy Premium Calculator (Purchase)</b></font> <form name="formTitleCalc"> <table border="0" width="480" cellpadding="0" cellspacing="0"> <tr> <td> <table border="0" width="100%" cellpadding="2" cellspacing="2" bgcolor="#FDFCF0"> <tr> <td width="54%" align="right"><b><font size="2" face="Arial, Helvetica, sans-serif">What is your Purchase Price?</font></b></td> <td width="46%"> <input type="text" name="purchPrice"> </td> </tr> <tr align="center"> <td colspan="2"> <input type="Reset" value="Clear Fields"> <input type="button" value="Calculate" name="Calculate" onClick="calculateValues()"> </td> </tr> </table> <table border="0" width="100%" cellpadding="2" cellspacing="2"> <tr> <td colspan="2"> <hr size="1" noshade> <font size="2" face="Arial, Helvetica, sans-serif">The combo title insurance premium includes the required lenders policy and also an optional owners policy.</font> </td> </tr> <tr> <td width="54%" align="right" bgcolor="#FDFCF0"><b><font face="Arial, Helvetica, sans-serif" size="2">The Combo Policy Premium<br> for this Purchase is </font></b></td> <td width="46%" bgcolor="#FDFCF0"> <input type="text" name="titleCombo" readonly> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> <hr size="1" noshade> <font size="2" face="Arial, Helvetica, sans-serif"><i><b>Your Title fees for the transaction you created are as follows:</b></i></font><br> <br> <table border="0" width="100%"> <tr> <td width="35%" bgcolor="#FDFCF0"><font size="2" face="Arial, Helvetica, sans-serif">Closing Fee:</font></td> <td width="20%" bgcolor="#FDFCF0"> <input type="text" name="closingFee" size="10" readonly> </td> <td bgcolor="#FDFCF0" valign="top"><font face="Arial, Helvetica, sans-serif"> </font></td> </tr> <tr bgcolor="#E9E8DD"> <td width="35%"><font size="2" face="Arial, Helvetica, sans-serif">Title Search:</font></td> <td width="20%"> <input type="text" name="abstractTitleSearch" size="10" readonly> </td> <td valign="top"> </td> </tr> <tr> <td width="35%" bgcolor="#FDFCF0"><font size="2" face="Arial, Helvetica, sans-serif">Florida Form 9:</font></td> <td width="20%" bgcolor="#FDFCF0"> <input type="text" name="floridaForm9" size="10" readonly> </td> <td bgcolor="#FDFCF0" valign="middle"> </td> </tr> <tr bgcolor="#E9E8DD"> <td width="35%"><font size="2" face="Arial, Helvetica, sans-serif">Other Endorsements:</font></td> <td width="20%"> <input type="text" name="endorseMents" size="10" readonly> </td> <td valign="top"><font size="1" face="Arial, Helvetica, sans-serif">(Other Endorsements $50.00 each)</font></td> </tr> <tr> <td width="35%" bgcolor="#FDFCF0"><font size="2" face="Arial, Helvetica, sans-serif">Imaging Fee:</font></td> <td width="20%" bgcolor="#FDFCF0"> <input type="text" name="imageFee" size="10" readonly> </td> <td bgcolor="#FDFCF0" valign="top"> </td> </tr> <tr> <td width="35%" valign="top" bgcolor="#E9E8DD"><font size="2" face="Arial, Helvetica, sans-serif">Courier/Package Handling:</font></td> <td width="20%" valign="top" bgcolor="#E9E8DD"> <input type="text" name="counterPackageHandling" size="10" readonly> </td> <td bgcolor="#E9E8DD" valign="top"> </td> </tr> <tr bgcolor="#E9E8DD"> <td width="35%" valign="top" bgcolor="#FDFCF0"><font size="2" face="Arial, Helvetica, sans-serif">Wire Service Fee:</font></td> <td width="20%" valign="top" bgcolor="#FDFCF0"> <input type="text" name="wireFee" size="10" readonly> </td> <td valign="top" bgcolor="#FDFCF0"> <font size="1" face="Arial, Helvetica, sans-serif"> </font></td> </tr> <tr> <td colspan="3"> <hr size="1" noshade> </td> </tr> <tr bgcolor="#FDFCF0"> <td width="35%" bgcolor="#E9E8DD"><b><font size="2" face="Arial, Helvetica, sans-serif">Total:</font></b></td> <td width="20%" bgcolor="#E9E8DD"> <input type="text" name="closingTotal" size="10" readonly> </td> <td bgcolor="#E9E8DD"><font face="Arial, Helvetica, sans-serif"> </font></td> </tr> </table> <p><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><br> Disclaimer:</b> Due to unforeseen variables the above charges are our best estimate, if you need a precise quote please call one of our closers to discuss your particular file. </font></p> </td> </tr> </table> </td> </tr> </table> </form> </td> </tr> </table> </td> <td width="105"> </td> </tr> </table>
World of Warcraft - Resources (items,quests,mods). itemvault.com
ArcadeApe.com Tons of free games, come and monkey around!
Customize your MySpace with our tips and tricks! MySpaceApe.net
twincitiesforum.com A Minnesota general chat forum.
-
Jun 4, 2008, 21:00 #2
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
You'll be wanting something like this:
Code javascript:v03 = (titleCombo * 0.1).toFixed(2);
Which rounds the floating-point value to 2 decimal places.Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Jun 5, 2008, 07:37 #3
- Join Date
- Jun 2004
- Location
- Fantastic US of A
- Posts
- 124
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
World of Warcraft - Resources (items,quests,mods). itemvault.com
ArcadeApe.com Tons of free games, come and monkey around!
Customize your MySpace with our tips and tricks! MySpaceApe.net
twincitiesforum.com A Minnesota general chat forum.
Bookmarks