View Single Post
Old 10-11-2012, 07:35 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
As you are not actually submitting a form (to a server) you should use <input type = "button" instead of "submit".

document.write() is obsolete - use DOM methods such as innerHTML to display the result of the calculation in a <span>

Code:
document.getElementById("result").innerHTML = payment.toFixed(2);  // display 2 decimal places
It would also be a good idea to verify that the values entered by the users are numbers.

Your variable principal is defined by has no value (you call it amount elsewhere).

Assigning a name to a form is now deprecated - prefer to use id instead. You can still refer to the form by document.forms[0] if you wish.

Finaly, it is a bad idea to use the same name (amount, interest, months) for a Javascript variable and an HTML element.


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote