Forum Moderators: coopster
When I run the program I get a display on the screen of "59.90" which is correct.
But when I insert the $total variable into my email page the variable $total writes "<script language=javascript>document.write(subtotal);</script>" to my email instead of the value.
Can anybody help.
Thanks
You need a way to get the variable back onto the server, so PHP can use it.
The best way I have found for a project I did was to use cookies. Since both JavaScript and PHP can read these, create one using JavaScript to store the total figure. Then on a new page, put in some PHP to read the cookie.
A reverse method to do this I have recently devised, is to have a variable in PHP and put it in a hidden form input. Then you can use JavaScript to read the value of the input, if it has an ID.
So it's possible to pass variables from JavaScript to PHP and back! Messy, but sometimes it has to be done.
see this example. (I got the user screen resolution from javascript and then passing it to php)
File a.html
<HTML>
<TITLE>Getting screen resolution........ Please wait....................</TITLE>
<!--
no personal urls please
-->
<HEAD>
<script language="javascript">
<!--
writeCookie();
function writeCookie()
{
var today = new Date();
var the_date = new Date("December 31, 2099");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "ur_width=" + screen.width ;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie
var the_cookie = "ur_height=" +screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie
location = 'b.php';
}
//-->
</script>
</HEAD>
<BODY>
Detecting your screen resolution .........<br>Please wait.....................................
</BODY>
</HTML>
File b.php
<?php
if(isset($_COOKIE["ur_width"]) and isset($_COOKIE["ur_height"])){
$ur_width = $HTTP_COOKIE_VARS["ur_width"];
$ur_height = $HTTP_COOKIE_VARS["ur_height"];
} else {
header("Location: a.html");
}
//delete the cookie
setcookie("ur_width",'',time()-3600);
setcookie("ur_height",'',time()-3600);
?>
[edited by: coopster at 4:46 pm (utc) on Nov. 22, 2005]
[edit reason] removed ulr per TOS [webmasterworld.com] [/edit]