Nalaka526
Nalaka526

Reputation: 11464

Get jQuery UI Datepicker selected date to a PHP Session variable?

How to get jQuery UI Datepicker selected date to a PHP Session variable when a date selected by user?

Upvotes: 2

Views: 3912

Answers (2)

dknaack
dknaack

Reputation: 60466

Description

You can do this using Ajax. After the Datepicker is closed you can set the Session Variable using a Ajax call.

You can use the DatePicker event onClose if you want to set the variable after the dialog is closed or onSelect after a date is selected. I would prefer the onClose event.

Sample

jQuery

$('.selector').datepicker({
   onClose: function(dateText, inst) { 
      $.post("/backend.php", {"VariableName": dateText});
   }
});

PHP (backend.php)

<?php
    // set the variable
    $_SESSION['VariableName'] = $_POST['VariableName'];
?>

More Information

Upvotes: 1

Simon Edstr&#246;m
Simon Edstr&#246;m

Reputation: 6619

Make an AJAX call when the onSelect is trigged.. Just dummy code you can play with:

        $('.selector').datepicker({
                 onSelect: function(dateText, inst) { 
                       $.ajax({
                             url: "myPHPscript.php?selecteddate=" + dateText,
                               success: function(){
                                 $(this).addClass("done");
                            }
                        });
                     }
        });

Upvotes: 3

Related Questions