DBookatay Posted March 30, 2008 Share Posted March 30, 2008 I found (ok ok, stole) a finance calculator script from MSN Auto http://autos.msn.com/loancalc/newloan.aspx, (Bill Gates stole from everyone else, it's just a little payback...) and need to add new fields to it to use form my application. Can someone please help? I want to add: Additional months: 30 and 54, but the script will not allow it Sales tax: 1 of 4 percentages: 6.000%, 7.375%, 8.125% or 8.375% (which the user would select based by an <select name="calcTax"></select>) Registration: 1 of 6 choices: $45, $60, $85, $120, $160, $210 (again controlled by <select name="calcReg"></select>) Can someone with java experience please help me with this, it would be greately apprechiated... Link to comment https://forums.phpfreaks.com/topic/98578-help-modifing-an-existing-script/ Share on other sites More sharing options...
DBookatay Posted March 30, 2008 Author Share Posted March 30, 2008 Can someone please help? I completely forgot to include the code: <script language="javascript"> var g_fRateStep = 0.05; // The smallest amount the interest rate can be modified by var g_nRateMultiple = 120; var g_nTermMultiple = 5; var g_strMonthly = 0; // Used by UpdateTotalCost (so that we don't need to interrogate the UI when the Monthly Payment is the target value) var g_fPurchasePrice = 0; // Install event handlers... window.onload = OnFormLoad; function OnFormLoad(event) { UpdateTargetValue(); document.LoanCalcForm.elements[2].focus(); } function OnResize(event) { document.location.reload(false); } function UpdateTargetValue() { UpdateMonthly(); } function FormatCurrency(strValue) { var strDecimalSeparator = '.'; var strThousandSeparator = ','; var nPos = strValue.indexOf('.'); var nLen = parseInt(strValue, 10).toString().length; if (nPos > 0) strValue = strValue.substr(0, nPos) + strDecimalSeparator + strValue.substr(nPos + 1, strValue.length - nPos); else nPos = strValue.length; while (nLen > 3) { nPos -= 3; strValue = strValue.substr(0, nPos) + strThousandSeparator + strValue.substr(nPos, strValue.length - nPos + 1); nLen -= 3; } return '$' + strValue; } function ChangeCalcType(strType) { var strExtra; if (strType == 'monthly') { return; strExtra = '&price=' + g_fPurchasePrice.toString(); } else { strExtra = '&pmt=' + (Math.round(g_strMonthly)).toString(); } location.href='/loancalc/newloan.aspx?calc=' + strType + '&dp=' + (document.LoanCalcForm.elements[2].value).toString() + '&trm=' + g_nTermMultiple.toString() + '&int=' + g_nRateMultiple.toString() + strExtra; } function UpdateTotalCost() { var nDownPayment = isNaN(parseInt(document.LoanCalcForm.elements[2].value, 10)) ? 0 : parseInt(document.LoanCalcForm.elements[2].value, 10); var nTerm = g_nTermMultiple * 12; var fMonthlyPayment = parseFloat(g_strMonthly); var fTotalCost = parseFloat(parseInt(nDownPayment, 10) + (fMonthlyPayment * nTerm)); fTotalCost = Math.round(fTotalCost); document.all.TotalCost.innerHTML = '<span class="bignum"><nobr>' + FormatCurrency(fTotalCost.toString()) + '</nobr></span>'; } function UpdatePrice() { var fRate = g_nRateMultiple * g_fRateStep; var nTerm = g_nTermMultiple * 12; var nDownPayment = isNaN(parseInt(document.LoanCalcForm.elements[2].value, 10)) ? 0 : parseInt(document.LoanCalcForm.elements[2].value, 10); var nPayment = isNaN(parseInt(document.LoanCalcForm.elements[3].value, 10)) ? 0 : parseInt(document.LoanCalcForm.elements[3].value, 10); var fMonthlyRate = (fRate * 0.01) / 12.0; var fPower = Math.pow(1.0 + fMonthlyRate, -nTerm); var fPrice = parseInt((fMonthlyRate == 0 ? ((nPayment * nTerm) + nDownPayment) : ((nPayment * ((1.0 - fPower) / fMonthlyRate)) + nDownPayment)), 10); g_fPurchasePrice = fPrice; document.all.Price.innerHTML = '<span class="bignum"><nobr>' + FormatCurrency(parseInt(fPrice, 10).toString()) + '</nobr></span>'; UpdateTotalCost(); } function UpdateMonthly() { var fRate = g_nRateMultiple * g_fRateStep; var nTerm = g_nTermMultiple * 12; var nDownPayment = isNaN(parseInt(document.LoanCalcForm.elements[2].value, 10)) ? 0 : parseInt(document.LoanCalcForm.elements[2].value, 10); var nPrice = isNaN(parseInt(document.LoanCalcForm.elements[3].value, 10)) ? 0 : parseInt(document.LoanCalcForm.elements[3].value, 10); if (nDownPayment > nPrice) nDownPayment = nPrice; var fMonthlyRate = (fRate * 0.01) / 12.0; var fPower = Math.pow(1.0 + fMonthlyRate, -nTerm); var fMonthly = (fPower == 1.0 ? (nPrice - nDownPayment) / nTerm : (nPrice - nDownPayment) * (fMonthlyRate / (1.0 - fPower))) ; if(fMonthly.toString().substr(0, 1) == '.') fMonthly = '0' + fMonthly.toString(); g_strMonthly = parseInt(fMonthly, 10).toString() + (Math.round((fMonthly - parseInt(fMonthly, 10)) * 100) / 100).toString().substr(1, 3); if ((g_strMonthly.toString().indexOf('.', 0) > 0) && (g_strMonthly.toString().length - g_strMonthly.toString().indexOf('.', 0) == 2)) g_strMonthly = g_strMonthly.toString() + '0'; document.all.Monthly.innerHTML = '<span class="bignum"><nobr>' + FormatCurrency(g_strMonthly) + '</nobr></span>'; UpdateTotalCost(); } function UpdateRate(bDoUpdate) { with (document.LoanCalcForm.elements[4]) { var fTemp = options[selectedIndex].value / 0.05; g_nRateMultiple = fTemp; if (g_nRateMultiple - parseInt(fTemp) > 0) g_nRateMultiple = parseInt(g_nRateMultiple) + 1; } if (bDoUpdate) UpdateTargetValue(); } function UpdateTerm(bDoUpdate) { with (document.LoanCalcForm.elements[5]) { var fTemp = options[selectedIndex].value / 12; g_nTermMultiple = fTemp; if (g_nTermMultiple - parseInt(fTemp) > 0) g_nTermMultiple = parseInt(g_nTermMultiple) + 1; } if (bDoUpdate) UpdateTargetValue(); } function ValidKey(nKeyCode, bShift, bCTRL) { if (nKeyCode != 37 && // Left cursor nKeyCode != 39 && // Right cursor nKeyCode != 8 && // Backspace nKeyCode != 9 && // Tab nKeyCode != 46 && // Delete nKeyCode != 16 && // Shift nKeyCode != 35 && // End nKeyCode != 36 && // Home (nKeyCode < 48 || nKeyCode > 57)) // 0 - 9 return false; else return true; } function Validate() { var nKeyCode = window.event.keyCode; var bShift = window.event.shiftKey; var bCTRL = window.event.ctrlKey; if (!ValidKey(nKeyCode, bShift, bCTRL)) return false; else return true; } function UpdateDownPayment() { var nDownPayment = isNaN(parseInt(document.LoanCalcForm.elements[2].value, 10)) ? 0 : parseInt(document.LoanCalcForm.elements[2].value, 10); var nPurchasePrice = parseInt(document.LoanCalcForm.elements[3].value, 10); UpdateMonthly(); } function Update() { var nDownPayment = parseInt(document.LoanCalcForm.elements[2].value, 10); var nPurchasePrice = parseInt(document.LoanCalcForm.elements[3].value, 10); UpdateMonthly(); } </script> Link to comment https://forums.phpfreaks.com/topic/98578-help-modifing-an-existing-script/#findComment-504746 Share on other sites More sharing options...
DBookatay Posted April 2, 2008 Author Share Posted April 2, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/98578-help-modifing-an-existing-script/#findComment-507137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.