0

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

Tom Bartel
  • 2,283
  • 1
  • 15
  • 18
akano1
  • 40,596
  • 19
  • 54
  • 67

3 Answers3

1

Yes. See How to get JavaScript function data into a PHP variable

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

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
  • 11,419
  • 5
  • 44
  • 69
  • is it possible to have sth like delivery; if I include the script in the php file, thanks – akano1 Nov 25 '09 at 10:50
  • 1
    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. – Quentin Nov 25 '09 at 10:52
0

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().

Tom Bartel
  • 2,283
  • 1
  • 15
  • 18