Page 1 of 1

newbie trying to modify a php mortgage calculator script

Posted: Mon Jul 02, 2007 10:39 pm
by shinbet
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi
I'm new to php and i'm trying to modify a simple mortgage calculator script, the script calculates the total monthly mortgage payment cost, currently including tax and property insurance,
However i want to remove the tax and ins from the calculation?
I can remove the text boxes, but i can't seem to manage to remove the two fields from the calculation function?
here is a sample calculator the same as i am using http://www.fal-media.com/mambo/

and here is the code for it (its not too long)
Thank you for anyone who can point me in the right direction

Code: Select all

<?php
// $Id: mod_mortgage_calc.php,v 1.0 2004/may/28  $
/**
* Mortgage Calculator Module
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.0 $
**/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

// $content="<script language=\"JavaScript\" type=\"text/javascript\" src=\"mod_mortgage_calc/mtg_calc.js\"></script>\n";
$content="<FORM NAME=\"temps\">\n";
$content.="Enter you own values to automatically calculate your total monthly payment<hr>\n";
$content.="<table border=\"0\" cellpadding=\"0\">\n";
$content.="  <tr>\n";
$content.="    <td>Years:</td>\n";
$content.="    <td><INPUT TYPE=\"TEXT\" NAME=\"YR\" onChange=\"dosum()\" SIZE=\"6\" VALUE=\"30\" style=\"border-style: outset; border-width: 1\"></td>\n";
$content.="  </tr>\n";
$content.="  <tr>\n";
$content.="    <td>Int Rate:</td>\n";
$content.="    <td><INPUT TYPE=\"TEXT\" NAME=\"IR\" onChange=\"dosum()\" SIZE=\"6\" VALUE=\"5.5\" style=\"border-style: outset; border-width: 1\"></td>\n";
$content.="  </tr>\n";
$content.="  <tr>\n";
$content.="    <td><b>Amount:</b></td>\n";
$content.="    <td><INPUT TYPE=\"TEXT\" NAME=\"LA\" onChange=\"dosum()\" SIZE=\"6\" VALUE=\"250000\" style=\"border-style: outset; border-width: 2\"></td>\n";
$content.="  </tr>\n";
$content.="  <tr>\n";
$content.="    <td>Tax/yr:</td>\n";
$content.="    <td><INPUT TYPE=\"TEXT\" NAME=\"AT\" onChange=\"dosum()\" SIZE=\"6\" VALUE=\"3500\" style=\"border-style: outset; border-width: 1\"></td>\n";
$content.="  </tr>\n";
$content.="  <tr>\n";
$content.="    <td>Ins/yr:</td>\n";
$content.="    <td><INPUT TYPE=\"TEXT\" NAME=\"AI\" onChange=\"dosum()\" SIZE=\"6\" VALUE=\"1200\" style=\"border-style: outset; border-width: 1\"></td>\n";
$content.="  </tr>\n";
$content.="  <tr>\n";
$content.="    <td><b>Payment:</b></td>\n";
$content.="    <td><INPUT TYPE=\"TEXT\" NAME=\"MP\" SIZE=\"6\" style=\"border-style: outset; border-width: 2\"></td>\n";
$content.="  </tr>\n";
$content.="</table>\n";
$content.="<INPUT TYPE=\"hidden\" NAME=\"PI\" SIZE=\"1\">\n";
$content.="<INPUT TYPE=\"hidden\" NAME=\"MT\" SIZE=\"1\">\n";
$content.="<INPUT TYPE=\"hidden\" NAME=\"MI\" SIZE=\"1\">\n";
$content.="</FORM>\n";
?>

<script language="Javascript">
<!--


// =============================
// Calc functions for Mortgage Payments
// =============================



function floor(number)
{
  return Math.floor(number*Math.pow(10,2) + 0.5)/Math.pow(10,2);
}

function dosum()
{
  var MI = document.temps.IR.value / 1200;
  var base = 1;
  var mbase = 1 + MI;
  for (i=0; i<document.temps.YR.value * 12; i++)
  {
    base = base * mbase
  }
  document.temps.PI.value = floor(document.temps.LA.value * MI / ( 1 - (1/base)))
  document.temps.MT.value = floor(document.temps.AT.value / 12)
  document.temps.MI.value = floor(document.temps.AI.value / 12)
  var dasum = document.temps.LA.value * MI / ( 1 - (1/base)) +
	document.temps.AT.value / 12 +
	document.temps.AI.value / 12;
  document.temps.MP.value = floor(dasum);
}



//-->
</script>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jul 02, 2007 10:42 pm
by Benjamin
WOW I thought I had seen it all. Building the HTML in PHP then doing the calculations in Javascript. 8O

That is a Javascript issue.

Posted: Tue Jul 03, 2007 10:49 am
by shinbet
Sorry!