Reputation: 11464
How to get jQuery UI Datepicker selected date to a PHP Session variable when a date selected by user?
Upvotes: 2
Views: 3912
Reputation: 60466
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.
jQuery
$('.selector').datepicker({
onClose: function(dateText, inst) {
$.post("/backend.php", {"VariableName": dateText});
}
});
PHP (backend.php)
<?php
// set the variable
$_SESSION['VariableName'] = $_POST['VariableName'];
?>
Upvotes: 1
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