View Full Version : Javascript calculated total: setting it in a session?

12-15-2006, 11:00 PM
I'm very confused and I can't seem to find any tutorials on this.

What I have is an ecommerce page with multiple cd's on it. When users make their selection and click "calculate", a script runs that calculates costs, shipping, tax, etc.

Now I have this total sitting in an input field and what I want to do is have it so I can display it on the next page, which is the customer information page. Essentially, I want to store this calculated value in a php session and make it so I can display it whenever I need to refer to it on sequential pages.

Sorry if that was kind of hard to understand, as I'm a bit confused on the best way to execute this.

Any help would be greatly appreciated.

12-15-2006, 11:37 PM
If your value is in a input field like this,

<form name="xxx" action="form_receive.php" method="post">
<input type="text" name="total" />

then submit the form and get the value via $_POST, like this:


$_SESSION['total'] = $_POST['total'];


You could also pass the variable from page to page in the URL as a GET var, it might be easier...


12-16-2006, 02:15 AM
hmm, I'm having a hard time understanding this.

1. I'd put

at the top of the first page, and no other php.

2. On the second page,

$_SESSION['gtotal'] = $_POST['gtotal'];
at the top.

..but how would I print the actual total value on the second page?

<?php echo $gtotal; ?>

Like that?

*scratches head*

12-16-2006, 02:19 AM
echo $_SESSION['gtotal'];


12-16-2006, 02:27 AM
I love you.

12-16-2006, 02:29 AM
Glad I could help...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum