Welcome to Gaia! ::

My Design :: Web and Graphic Design [HTML CSS PHP]

Back to Guilds

XHTML, CSS, jQuery, Javascript, PHP, mySQL, MORE! 

Tags: design, graphics, html, jquery, javascript 

Reply My Design
I need help with my Javascript code

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

drugdealerguy666

PostPosted: Sat Apr 21, 2007 12:40 am


I am working on a javascript loan calculator, but i cant get it to work right





JavaScript Loan Calculator



<!--
This is an HTML form that allows the user to enter data and allows
Javascript to display the results it computes back to the user. The
form elements are embedded in a table to improve their apperance.
The fom itself is given the name "loandata" , and the fields within
are given names such as "interest" and "years". These
field names are used in the Javascript code that follows the form.
Note that some of the form elements define "onchange" or "onclick"
event handlers. These specify strings of Javascript code to be
executed when the user enters data or clicks on a button.
-->





































Enter Loan Information:

1) Amount of the loan (any currency):


2) Annual percentage rate of interest:


3) Payment period in years:




Payment Information:

4) Your monthly payment:

$

5) Your payment:

$

6) Your total interest payments:

$



language="javascript">
/*
*This is the Javascript function that makes the example work. Note that
*this script defines the calculate() function called by the event
*handlers in the form. The function reads values from the form
* fields using the names defined in the previous HTML code. It outputs
*its results into the named elements.
*/
function calculate() {
// Get the user's input from the form. Assume it is all valid.
// Convert interest from a percentage to a decimal, and convert from
// an annual rate to a monthly rate. Convert payment period in years
// to the number of monthly payments.
var principal = document.loandata.principal.value;
var interest = document.loandata.interest.value / 100 / 12;
var payments = document.loandata.years.value * 12

// Now compute the monthly payment figure, using esoteric math.
var x = Math.pow(1 + interest, payments)
var monthly = (principal*x*interest)/(x-1)

// Get names elements from the form.
var payment = document.getElementById("payment")
var total = document.getElementById("total")
var totalinterest = document.getElementById("totalinterest")

// Check that the result is a finite number. if so, display the
// results by setting the HTML content of each element.
if (isFinite(monthly)) {
payment.innerHTML = monthly.toFixed(2)
total.innerHTML = (montly * payments).toFixed(2)
totalinterest.innerHTML = ((monthly*payments)-principal).toFixed(2)
}
// Otherwis, the user's input was probably invalid, so display nothing.
else {
payment.innerHTML = "";
total.innerHTML = "";
totalinterest.innerHTML = "";
}
}




PostPosted: Sat Apr 21, 2007 12:41 am


Please help

drugdealerguy666


Zionna

PostPosted: Sun Apr 22, 2007 3:15 am


Can we have some example figures??

ie values for the first 3 boxes and then what the expected value should be (and how it should be worked out??)
Reply
My Design

 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum