External Variables?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

External Variables?

Post by ianripping »

I have this html / javascript : -
<!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" size="20"><br>
months<input type ="text" name="b" size="20"><br>
amount with interests<input type ="text" name="ans" size="20"><br>
<input type ="button" onClick="a_int_b(this.form)">
</form>
</body>
</html>

But I want the 1.00482 to be saved in an external file, eg txt or xls. So it can be changed easily.

I've heard theat this cant be done in java and would want to know if it can be done in php?
User avatar
Pointybeard
Forum Commoner
Posts: 71
Joined: Wed Sep 03, 2003 7:23 pm
Location: Brisbane, AUS
Contact:

Post by Pointybeard »

This what you mean?

Code: Select all

<!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*form.a_constant.value;
}
form.ans.value = c.toFixed(2);
}
//-->
</script>
</head>
<body> 

<?php

	$handle = fopen("value.txt", "r");
	$buffer = fgets($handle, 4096);	
	
	define(CONST_VALUE, trim($buffer));		
	
	


?>	

<form>
<input type=hidden name="a_constant" value="<?= CONST_VALUE ?>" />
amount<input type ="text" name="a" size="20"><br>
months<input type ="text" name="b" size="20"><br>
amount with interests<input type ="text" name="ans" size="20"><br>
<input type ="button" onClick="a_int_b(this.form)">
</form>
</body>
</html>
Hope thats right. Just chuck yer value into 'value.txt' and have it in the same dir as the script

-PB
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Post by ianripping »

i have tried that but it returns the value NaN, every time. I just whacked the code into a html file and uploaded it with a value.txt file with the value inserted. Is this right?
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

ianripping wrote: I just whacked the code into a html file and uploaded it with a value.txt file with the value inserted. Is this right?
Have you uploaded to a server running PHP ? Have you renamed your file from .html to .php

Dr Evil
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Post by ianripping »

Just had to rename to .php. Done, brill thnax!
User avatar
Pointybeard
Forum Commoner
Posts: 71
Joined: Wed Sep 03, 2003 7:23 pm
Location: Brisbane, AUS
Contact:

Post by Pointybeard »

no problem. :p
Post Reply