Thread: Resolved HTML form and Javascript
View Single Post
Old 11-12-2012, 12:02 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by adityavishnu View Post
I don't know how to declare it as global variable but whats the matter with this case if p n r are declared globally

Code:
var p=Number(document.getElementById("pa").value);
var n=Number(document.getElementById("ny").value);
var r=Number(document.getElementById("ri").value);
function si() 
{
var s=p*n*r/100;
alert("Total Interest Amount is "+s.toFixed(2));
}

function ta() {
var s=p*n*r/100;
var t = p+s;
alert("Total Amount Payable is "+t.toFixed(2));
}
If you do not know how to declare p, n and r as global variables then indeed you may not be able to see the problem.

Declare p, n and r as global variables (look up how to do this very basic thing) and then test your script using alerts to inspect the value of the various variables as the script executes. And/or use your error console to identify errors.

I'll say it one more time - Your main problems are that you are trying to get the values of p, n and r as soon as the page loads (when they do not even exist at that moment) instead of when the function runs.

I gave you a full solution in Post #2. If that displeases you in some way, then that is OK by me. But if you are unwilling to take advice then it is pointless asking for help so you must proceed on your own.
__________________

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.

Last edited by Philip M; 11-12-2012 at 12:05 PM..
Philip M is offline   Reply With Quote