/    Sign up×
Community /Pin to ProfileBookmark

Updating Variables

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

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 03.2004 — Hi!

You won't need an admin! Please look at this:
[code=php]
<!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>
[/code]

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
Copy linkTweet thisAlerts:
@ianrippingauthorFeb 03.2004 — 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?
Copy linkTweet thisAlerts:
@PittimannFeb 03.2004 — 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
Copy linkTweet thisAlerts:
@ianrippingauthorFeb 03.2004 — ok cool php sounds great, any good websites to get me started tyhat you recommend?
×

Success!

Help @ianripping spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...