Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Title Insurance Calculator - HELP

Status
Not open for further replies.

demiurgik

Technical User
Jul 25, 2003
10
US
the formula for the title insurance calculator is as follows:

up to the first $100,000 $5.75 per $1,000.00

over 100,000 and up to $1 Million $5.00 per $1,000.00

over $1 Million and up to $5 Million $2.50 per $1,000.00

over $5 Million and up to $10 Million $2.25 per $1,000.00

over $10 Million $2.00 per $1,000.00

it is divided into fraction of $100.00 however, any fraction of $100 should be considered as a full $100.00 for purpose of Calculating Premiums.

This will give us the promulgated rate we then want a separate column to show what they would be saving with us. We will then discount by 40% so a $1,000 policy would cost $600

I have code for the entire thing except the discounted 40% - I need help with this part.

Can anyone please help me?
 
Math is fun!

Before you do that final (*0.6) multiplcation, multiply everything by some fixed number such that all your operations happen in integers to avoid any floating point errors.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Edward,
Thanks for your tip, do you think I could post the code and you could help me with the last portion.
My partner bailed on the project so now I'm left with something I don't really understand.

I know that I have to take the answer from the first part of the equation and multiply that by the .60, but I'm not quite sure how to display it in a corresponding text box.

Any help would be greatly appreciated!!!
 
Yeah, post what you feel like posting and I'll take a look.

When you post it, please put it between "
Code:
" blocks so it doesn't get all Ashcrofted.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Oy, I mean to hit "Preview" to make sure the codes didn't get invisibled, but the darn flesh was unwilling.

Be sure to post code between
[ignore]
Code:
[/ignore]
and
[ignore]
[/ignore]
tags to preserve formatting and such

Cheers,

Edward

[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
The last part I need to do is to take the Purchase Price Cost and multiply that by .60 and display it in a text box already named NDTECost. Thanks so much for your time.

General Variables

var MAX_MORTGAGE_DIGITS = 30
var TX_TYPE_DOC_STAMP_ON_DEED = 1
var TX_TYPE_DOC_STAMP_ON_MORTGAGE = 2
var TX_TYPE_INTANGIBLE_TAX = 3
// dade county documentary stamp on single family home
var TX_TYPE_DADE_SINGL_DSTAMP_ON_DEED = 4
// dade county documentary stamp on non-single family home
var TX_TYPE_DADE_NONSINGL_DSTAMP_ON_DEED = 5
var FL_INTANGIBLE_TAX_MULTIPLIER = 0.002
var FL_DOC_STAMP_ON_MORT_MULTIPLIER = 0.35
var FL_DOC_STAMP_ON_DEED_MULTIPLIER = 0.70
// multiplier for dade county documentary stamp on single family home
var DADE_FL_SINGL_DSTAMP_ON_DEED_MULTIPLIER = 0.60
// multiplier for dade county documentary stamp on non-single family home
var DADE_FL_NONSINGL_DSTAMP_ON_DEED_MULTIPLIER = 1.05
var FL_DOC_STAMP_MORT_PER_VALUE = 100.00
var FL_DOC_STAMP_DEED_PER_VALUE = 100.00
var ONE_HUNDRED_THOUSAND = 100000.00
var ONE_MILLION = 1000000.00
var FIVE_MILLION = 5000000.00
var TEN_MILLION = 10000000.00
var FL_UPTO_100K_MULTIPLIER = 5.75
var FL_OVER_100K_UPTO_1M_MULTIPLIER = 5.00
var FL_OVER_1M_UPTO_5M_MULTIPLIER = 2.50
var FL_OVER_5M_UPTO_10M_MULTIPLIER = 2.25
var FL_OVER_10M_MULTIPLIER = 2.00
var FL_UPTO_100K_PER_VALUE = 1000.00
var FL_OVER_100K_UPTO_1M_PER_VALUE = 1000.00
var FL_OVER_1M_UPTO_5M_PER_VALUE = 1000.00
var FL_OVER_5M_UPTO_10M_PER_VALUE = 1000.00
var FL_OVER_10M_PER_VALUE = 1000.00
var FL_UPTO_100K_ADDITIONAL_AMOUNT = 0.00
var FL_OVER_100K_UPTO_1M_ADDITIONAL_AMOUNT = 575.00
var FL_OVER_1M_UPTO_5M_ADDITIONAL_AMOUNT = 5075.00
var FL_OVER_5M_UPTO_10M_ADDITIONAL_AMOUNT = 15075.00
var FL_OVER_10M_ADDITIONAL_AMOUNT = 26325.00
// florida insurance prim min cost
var FL_INS_PREM_MIN_COST = 100.00

Function:
calcFLInsurPremium

Description:
This function will calculate Mortgage Premium Cost on the given mortgage amount.

The algorithm used is:

POLICY AMOUNT
Up to $100,000.00 (Amount/1000.00) * 5.75)
Over $100,000.00 up to 1,000,000.00 575.00 + ((Amount-100,000.00/1000.00) * 5.00)
Over $1,000,000.00 up to 5,000,000.00 5075.00 + ((Amount-1,000,000.00/1000.00) * 2.50)
Over $5,000,000.00 up to 10,000,000.00 15075.00 + ((Amount-5,000,000.00/1000.00) * 2.25)
Over $10,000,000.00 up to 10,000,000.00 26325.00 + ((Amount-10,000,000.00/1000.00) * 2.00)



If minimum premium cost to charge is always $100.00.
Formal Arguments:
txObjPurchasePrice - a text object containg the Mortgage Purchase Price or Amount.
txObjCost - a text object whose value will be assigned the Cost amount calculated.

Return Type: Boolean

Return Values:
true - upon success
false - upon failure

function calcFLInsurPremium(txObjPurchasePrice, txObjCost)
{
var nMortgageAmount = new Number;
var nCost;
var txAmount = txObjPurchasePrice;
var txTmp;

// make sure its a number and its a valid mortgage number
if( isValidMortgageAmount(txAmount) == false )
{
txObjCost.value = "0.00";
// alert("Please enter a valid Purchase Price or Mortgage Amount!");
txObjPurchasePrice.focus();
return false;
}

// do the necessary calculations to determine the cost
nMortgageAmount = parseFloat(txAmount.value);

if( nMortgageAmount <= ONE_HUNDRED_THOUSAND )
{
// Up to $100,000.00 (Amount/1000.00) * 5.75)
if( nMortgageAmount <= FL_UPTO_100K_PER_VALUE)
{
nCost = FL_UPTO_100K_MULTIPLIER;
}
else
nCost = FL_UPTO_100K_ADDITIONAL_AMOUNT + ((nMortgageAmount/FL_UPTO_100K_PER_VALUE) * FL_UPTO_100K_MULTIPLIER);
}
else if( nMortgageAmount <= ONE_MILLION )
{
// Over $100,000.00 up to 575.00 + ((Amount-100,000.00/1000.00) * 5.00)
// 1,000,000.00

nCost = FL_OVER_100K_UPTO_1M_ADDITIONAL_AMOUNT + (((nMortgageAmount-ONE_HUNDRED_THOUSAND)/FL_OVER_100K_UPTO_1M_PER_VALUE) * FL_OVER_100K_UPTO_1M_MULTIPLIER);
}
else if( nMortgageAmount <= FIVE_MILLION )
{

// Over $1,000,000.00 up to 5075.00 + ((Amount-1,000,000.00/1000.00) * 2.50)
// 5,000,000.00

nCost = FL_OVER_1M_UPTO_5M_ADDITIONAL_AMOUNT + (((nMortgageAmount-ONE_MILLION)/FL_OVER_1M_UPTO_5M_PER_VALUE) * FL_OVER_1M_UPTO_5M_MULTIPLIER);
}
else if( nMortgageAmount <= TEN_MILLION )
{
// Over $5,000,000.00 up to 15075.00 + ((Amount-5,000,000.00/1000.00) * 2.25)
// 10,000,000.00

nCost = FL_OVER_5M_UPTO_10M_ADDITIONAL_AMOUNT + (((nMortgageAmount-FIVE_MILLION)/FL_OVER_5M_UPTO_10M_PER_VALUE) * FL_OVER_5M_UPTO_10M_MULTIPLIER);
}
else
{

// Over $10,000,000.00 up to 26325.00 + ((Amount-10,000,000.00/1000.00) * 2.00)

nCost = FL_OVER_10M_ADDITIONAL_AMOUNT + (((nMortgageAmount-TEN_MILLION)/FL_OVER_10M_PER_VALUE) * FL_OVER_10M_MULTIPLIER);

}

if( nCost < FL_INS_PREM_MIN_COST )
{
nCost = FL_INS_PREM_MIN_COST
}
// return the calculated value

txTmp = nCost.toString();
//alert(&quot;nCost = &quot; + nCost.toString());

//alert(&quot;txTmp before round = &quot; + txTmp);

rnd2DecPlaces(txTmp, txObjCost);
txObjPurchasePrice.focus();
return true;


} /**** calcFLInsurPremium ****/


function processFormSubmit(frmObj)
{
return false;
}
 
Can you post the lines from your HTML code that call these functions?

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
<HTML><HEAD><TITLE>Rate Calculator</TITLE>
<META http-equiv=Content-Type content=&quot;text/html; charset=windows-1252&quot;>
<META content=&quot;MSHTML 6.00.2726.2500&quot; name=GENERATOR>
<META content=FrontPage.Editor.Document name=ProgId>
<SCRIPT language=JavaScript src=&quot;Rate Calculator_files/MortCalcLib.js&quot;>
</SCRIPT>

<META content=&quot;pvfantea 111, default&quot; name=&quot;Microsoft Theme&quot;>
<META content=tlb name=&quot;Microsoft Border&quot;></HEAD>
<BODY text=#000000 vLink=#cc0000 aLink=#00cc33 link=#0000ff bgColor=#ffffff
background=&quot;Rate Calculator_files/bgw.gif&quot;>
<TABLE dir=ltr cellSpacing=0 cellPadding=0 width=&quot;100%&quot; border=0>
<TBODY>
<TR>
<TD vAlign=top width=24></TD>
<!--msnavigation-->
<TD vAlign=top>
<FORM name=ratescalc onsubmit=&quot;return false;&quot; action=Calculator.htm
method=post>
<FONT face=&quot;verdana, Arial, Helvetica&quot;><!-- ***************************** Calculator Starts Here ***************************** -->
</font>
<DIV align=center>
<CENTER>
<TABLE style=&quot;BORDER-LEFT: outset&quot; height=210 cellSpacing=0
borderColorDark=#FFFFFF cellPadding=0 width=600 borderColorLight=#FFFFFF
border=3>
<TBODY>
<TR>
<TD>
<TABLE style=&quot;BORDER-LEFT: outset&quot; height=210 width=600 align=center
border=0>
<THEAD>
<TR>
<TD> </TD>
</TR>
</THEAD> <TBODY>
<TR align=middle>
<TD>  </TD>
</TR>
<TR align=middle>
<TD>
<TABLE border=0 align=&quot;center&quot; width=&quot;600&quot;>
<TBODY>
<TR align=middle>
<TD align=middle width=&quot;195&quot;>
<div align=&quot;center&quot;><FONT
face=&quot;verdana, Arial, Helvetica&quot;><FONT face=Arial
size=2>Purchase Price or Mortgage Amount<BR>
(No Commas or Decimals) </FONT></FONT></div>
</TD>
<TD align=middle width=&quot;19&quot;> </TD>
<TD align=middle width=&quot;151&quot;>
<div align=&quot;center&quot;><FONT
face=&quot;verdana, Arial, Helvetica&quot;><FONT face=Arial
size=2>Premium, Stamps or Tax </FONT></FONT></div>
</TD>
<TD align=middle width=&quot;15&quot;> </TD>
<td width=&quot;130&quot;>
<div align=&quot;center&quot;> <font
face=&quot;verdana, Arial, Helvetica&quot;><font face=Arial
size=2>NDT&E</font></font><font face=&quot;Arial&quot; size=&quot;2&quot;></font></div>
</td>
</TR>
<TR align=left>
<TD align=left width=&quot;195&quot;>
<div align=&quot;center&quot;><FONT
face=&quot;verdana, Arial, Helvetica&quot;><SMALL><FONT
face=Arial>$ </FONT></SMALL>
<INPUT
onmouseover=&quot;window.status='Enter the Purchase Price or Mortgage Amount'&quot;
size=28 name=Purprice>
</FONT></div>
</TD>
<TD align=middle width=&quot;19&quot;><FONT
face=&quot;verdana, Arial, Helvetica&quot;>
<DIV align=center> <SMALL><FONT
face=Arial> </FONT></SMALL><SMALL><FONT
face=Arial>= </FONT></SMALL></DIV>
</FONT></TD>
<TD align=middle width=&quot;151&quot;>
<div align=&quot;center&quot;><FONT
face=&quot;verdana, Arial, Helvetica&quot;><SMALL><FONT
face=Arial>$ </FONT></SMALL>
<INPUT
onmouseover=&quot;window.status='The Calculated Cost will be recorded here'&quot;
style=&quot;TEXT-ALIGN: center&quot; value=0.00 name=PCCost>
</FONT></div>
</TD>
<TD align=middle width=&quot;15&quot;>
<div align=&quot;center&quot;>=</div>
</TD>
<td align=middle width=&quot;130&quot; valign=&quot;middle&quot;>
<div align=&quot;center&quot;> <font
face=&quot;verdana, Arial, Helvetica&quot;><small><font
face=Arial>$ </font><font
face=&quot;verdana, Arial, Helvetica&quot;>
<INPUT
onMouseOver=&quot;window.status='NDT&E Cost will be recorded here'&quot;
style=&quot;TEXT-ALIGN: center&quot; value=0.00 name=NDTECost>
</font></small> </font></div>
</td>
</TR>
</TBODY>
</TABLE>
<FONT
face=&quot;verdana, Arial, Helvetica&quot;>
<DIV align=center>
<P><BR>
</P>
</DIV>
</FONT>
<DIV align=center>
<TABLE align=center border=0>
<TBODY>
<TR align=middle>
<TD align=middle>
<div align=&quot;center&quot;><FONT
face=&quot;verdana, Arial, Helvetica&quot;><A
onclick=&quot;calcFLInsurPremium(document.ratescalc.Purprice, document.ratescalc.PCCost); return false;&quot;
href=&quot;javascript:&quot;><IMG height=45
src=&quot;Rate Calculator_files/buttpremium.gif&quot; width=191
border=0 name=b1></A></FONT></div>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>

</TR>
</TBODY>
</TABLE>
<FONT
face=&quot;verdana, Arial, Helvetica&quot;></FONT>
</TR>
</TBODY>
</TABLE>
<FONT
face=&quot;verdana, Arial, Helvetica&quot;></font>
</CENTER>
</DIV>
</FORM>
<FONT
face=&quot;verdana, Arial, Helvetica&quot;>  </FONT></TD>
</TR>
<!--msnavigation--></TBODY>
</TABLE>
</BODY></HTML>
 
This is really ugly. I'm digging through...

Does this actually run on the web or on a nonIE browser? There are pathnames with spaces and all those lines in the JS file pop up as errors all over the place.

I think your first problem is that you're using FrontPage to create a website. I highly recommend you find some other tool.

I'll let you know what I find, but I'm letting you know now that to even get the thing to run without errors, I'm dinkin' with all sorts of fiddly bits of code.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Okay, it's a mess and it fails to function because it can't find some other function.

I printed the code out and tacked it to the wall and threw a dart and it landed on this line:

Code:
txTmp = nCost.toString();

so I guess you can try changing that to

Code:
txTmp = (nCost * 0.6).toString();

Alternately, you can preceded it like this:
Code:
nCost =* 0.6;
txTmp = nCost.toString();

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
A URL with a space is an invalid URL.

Did the line change work?

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
sorry - try this link:


not really quite sure what the line change is doing, i need to take the answer that is produced in the middle box and multiply that by .6 and then display that number in the third box.
 
Is it supposed to always display &quot;0.00&quot; in the third box, no matter what I type?

When you run this from the link you posted above, what do you see in the other two boxes when you enter &quot;500000000&quot; in the first box and then click on the yellow image?

Have you tried running this under any browser other than IE?

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
i have not been able to program the code for the third box to display the correct information.

when you put 50000000 in the first box, the output in the second box is : 1006325.00

now based on 1006325.00 the third box should take that number and multiply it by .60 to get 603795.

i have not tried it in any other browser yet as i havent gotten the code complete.
 
I would suggest that you download a copy of Mozilla (for example) and try running your page under that as well. While you're still developing it. This way, you discover problems &quot;early&quot; and can fix them before you publish the page.

I realize you inherited this code. It is a complete mess and a real pain to trace through. Are you sure this isn't one of the runners-up in a most-obfuscated code contest?

As far as I can tell, there is no place at all where a value is even assigned to this text box except when it is constructed, where the &quot;0.00&quot; is assigned to it as a value.

Are you telling me that a person enters a single number in the first box, the second box gets populated by the formula in your first post, and then the third box gets populated by 60% of the second box? Is that all you want to do?

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Okay.

Find the code in your .js file that looks like this:

Code:
		} /**** rnd2DecPlaces ****/

and replace it with this:

Code:
                  var NDTECostValue = (txObjTo.value / 100) * 60;
                  if (!Number.prototype.toFixed)
                  {
                    Number.prototype.toFixed = function(decimals)
                    {

                    var decimals = decimals || 2 // defaults to two
                    var catalyst = Math.pow(10, decimals);

                    var fixedNum = Math.round(parseFloat(this) * catalyst) / catalyst;
                    var sFixedNum = new String(fixedNum)
                    var aFixedNum = sFixedNum.split(&quot;.&quot;)

                    var i = (aFixedNum[1]) ? aFixedNum[1].length : 0
                  // append decimal point if needed
                    if (i == 0) { sFixedNum += &quot;.&quot; }
                  // append zeros if needed
                    while (i < decimals) {
                      sFixedNum += &quot;0&quot;
                      i++
                      }
                    return sFixedNum 
                    }
                  }
                  document.ratescalc.NDTECost.value = (new Number(NDTECostValue).toFixed(2));
		} /**** rnd2DecPlaces ****/

Copy the code exactly from this post. It'll do the calculation and round to the nearest penny.

I'm using a method Xutopia posted in thread216-518499, which was a damn handy piece of code. All I did was wade through this spaghetti to figure out where to drop it.

Hope that helps!

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
do i place that whole code infront of what is already existing.

replace the existing variables for that section?
 
Just find the code line I specified and replace it the code I supplied.

You are replacing a single line of code with a bunch of lines of code. I even kept one line (the line you're replacing) as a reference point. This is as it should be. Do not change anything else in any other file at all. These are the files I downloaded from your website. I got the thing to work, so I know it's good.

I would recommend highly against monkeying around with other bits of the code. It is very messy. FrontPage is simply one of the best reasons I've encountered for the necessity of inventing some sort of a long-range slapping device. Wait, what am I thinking -- FrontPage is a long-range slapping device! [lol]

Hope that gets you where you want to be.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top