Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript calculated total: setting it in a session?

    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.

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    If your value is in a input field like this,

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

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

    form_receive.php
    PHP Code:

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

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

    Dan
    Last edited by whizard; 12-16-2006 at 12:47 AM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm, I'm having a hard time understanding this.


    1. I'd put
    PHP Code:
    <?php
    session_start
    ();
    ?>
    at the top of the first page, and no other php.


    2. On the second page,
    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['gtotal'] = $_POST['gtotal']; 
    ?>
    at the top.

    ..but how would I print the actual total value on the second page?
    PHP Code:
    <?php echo $gtotal?>
    Like that?

    *scratches head*

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    PHP Code:
    echo $_SESSION['gtotal']; 
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I love you.

  • #6
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Glad I could help...



    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •