tags:

views:

38

answers:

3

Hi, I have script and I'd like to know if it's possible the send the value of a variable to $_session,

 <script>

$(function() {

    var delivery = 0;
    $('#jcart-paypal-checkout').click(function() { 
     delivery = $('form#delivery2 input[type=radio]:checked').val();
     if(!delivery) {
      alert('Please choose a delivery option');
      return false;
     }else {
      <?php $_SESSION['shipping'] = ?> delivery;
     }


    });

});
</script>

I need to send the value of delivery in $_session['shipping'],

thanks

A: 

Yes, this is possible. But you'll have to call the PHP-Script with POST or GET Parameters.

Edit: But I don't think that you can put the variable directly into the session-array.

Bobby
is it possible to have sth like <?php $_SESSION['shipping'] = ?> delivery;if I include the script in the php file,thanks
amir
No. You can't have half of the statement running on one language on one computer and the other half running in a different language on a different computer.
David Dorward
A: 

For example, use $.get():

$(function() {
    var delivery = 0;
    $('#jcart-paypal-checkout').click(function() {      
        delivery = $('form#delivery2 input[type=radio]:checked').val();
        if(!delivery) {
                alert('Please choose a delivery option');
                return false;
        }
        $.get('putInSession.php', { d: delivery });
    });
 });

This snippet expects a script called "putInSession.php" on the server side, which should check the input parameter "d" and then

$_SESSION["shipping"] = $_GET["d"];

Optionally, you can specify a function that receives the result of the asynchronous request as third parameter of $.get().

Cheers, Tom

Tom Bartel