Quote:
Originally Posted by adityavishnu
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.