Click to See Complete Forum and Search --> : Updating Variables


ianripping
02-03-2004, 09:58 AM
I have this code:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var c;
function a_int_b(form){
c=0;
a=eval(form.a.value);
b=eval(form.b.value);
c=a;
for(var i = 0;i<b;i++){
c =c*1.00482;
}
form.ans.value = c.toFixed(2);
}
//-->
</script>
</head>
<body>
<form>
amount<input type ="text" name="a"><br>
months<input type ="text" name="b"><br>
amount with interests<input type ="text" name="ans"><br>
<input type ="button" onClick="a_int_b(this.form)">
</form>
</body>
</html>

Its basically a calculator to work out interest. I want a way to be able to update the variables like 1.00482 easily, without having to understand this code.

Ideally an external file that amins can access and change the 1.00482, eg txt file, xls file, etc

Pittimann
02-03-2004, 10:23 AM
Hi!

You won't need an admin! Please look at this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var yourPercent=0.00482//you can edit this as the monthly percentage
var c;
function a_int_b(form){
c=0;
a=eval(form.a.value);
b=eval(form.b.value);
c=a;
for(var i = 0;i<b;i++){
c =c+c*yourPercent;
}
form.ans.value = c.toFixed(2);
}
//-->
</script>
</head>
<body>
<form>
amount<input type ="text" name="a"><br>
months<input type ="text" name="b"><br>
amount with interests<input type ="text" name="ans"><br>
<input type ="button" onClick="a_int_b(this.form)" value="click">
</form>
</body>
</html>

The only thing you will have to change if you need a different interest rate is the variable yourPercent at the beginning of the script.

Does that help you?

Cheers - Pit

ianripping
02-03-2004, 12:55 PM
Well its useful but not what im looking for. Would like it if I could have the variable in a seperate file that I could access easily like txt file, that is linked to the scripting which locates and uses that file.

Any way possible?

Pittimann
02-03-2004, 01:05 PM
Hi!

Javascript is not really designed for what you want. It would be easy to do that by using a server side language (I personally prefer PHP). The interest rate (and other stuff, if necessary) could be stored in a text file or so and your html file could get the information from the server.

Cheers - Pit

ianripping
02-03-2004, 01:06 PM
ok cool php sounds great, any good websites to get me started tyhat you recommend?