Page 1 of 1

External Variables?

Posted: Thu Feb 05, 2004 3:20 am
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?

Posted: Thu Feb 05, 2004 5:58 am
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

Posted: Fri Feb 06, 2004 3:40 am
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?

Posted: Fri Feb 06, 2004 9:41 am
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

Posted: Fri Feb 06, 2004 11:24 am
by ianripping
Just had to rename to .php. Done, brill thnax!

Posted: Fri Feb 06, 2004 5:51 pm
by Pointybeard
no problem. :p