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 4 of 4
  1. #1
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts

    Passing on javascript values to PHP variable?

    The javascript code below adds values "sh" and "ww" for the text box named "shipping" and updates instantly when the user selects the location to ship to.


    document.autoSumForm.shipping.value = (sh * 1) + (ww * 1);

    I would like to pass that value on to a PHP variable. Can this be done?

    Thanks
    Leonard Whistler

  • #2
    New Coder
    Join Date
    Oct 2005
    Posts
    87
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You would need to either submit the form to a php script:
    Code:
    <form action="yourpage.php">
    or redirect to a php script using something like this:
    Code:
    window.open("yourpage.php?shipping="document.autoSumForm.shipping.value,"newWindow");
    Then in your php script use:
    Code:
    $input = $_REQUEST['shipping'];
    The input variable would then contain the shipping value from your form.

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Ok thanks pccode....

    I got it to work with code #1 and #3. And I will look into code #2 later on. I'm building a PHP, MySQL and Javascript shopping cart from scratch.
    Leonard Whistler

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could also store your calculated value as a 'hidden' type of input field and have it get passed along as a $_POST[] value...


  •  

    Posting Permissions

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