Reputation: 987
I am using jquery datepicker.
<form action="" method="get" name="date">
<br />
Start Date :<input type="text" name="sdate" id="sdate" />
End Date : <input type="text" name="edate" id="edate" />
</form>
I am setting a default date as soon as the page loads. And this date should be sent to php. But I am not able to do this without the help of submit button in the above form. How do I do this without the help of submit button? I am aware I need to use onClose option. But what should I write inside it so that the data is sent to PHP?
Here is the JS-
$("#sdate").datepicker({
"dateFormat" : "yy-mm-dd",
"onClose": ???
});
$("#edate").datepicker({
"dateFormat" : "yy-mm-dd",
"onClose": ???
});
$("#edate").datepicker("setDate","+0");
$("#sdate").datepicker("setDate","-7");
Upvotes: 0
Views: 1031
Reputation: 11749
If your datepicker is part of a form, you can do this...
onSelect: function (dateText, inst) {
$(this).parent('form').submit();
}
That will submit the parent form.
More info here....
http://mikemurko.com/general/jquery-ui-datepicker-form-submission-onselect/
More help here....almost same question...
jQuery Datepicker to Trigger a POST
Upvotes: 1
Reputation: 614
Hi you can use an AJAX call in the close function
onClose: function() {
//do ajax call here
$.ajax({
url: "test.php",
type: "post",
data: values,
success: function(){
alert("success");
},
error:function(){
alert("failure");
}
});
}
Upvotes: 0
Reputation: 455
You should provide a function that takes the date and make an Ajax call or if you want to send the two dates at the same time you should store both in variables and then make the Ajax call when the second close.
$("#sdate").datepicker({
"dateFormat" : "yy-mm-dd",
"onClose": function(date, obj){
jQuery.post('URL', {sDate: date}, function(data, textStatus, xhr) {
//If there is success
});
}
});
$("#edate").datepicker({
"dateFormat" : "yy-mm-dd",
"onClose": function(date, obj){
jQuery.post('URL', {eDate: date}, function(data, textStatus, xhr) {
//If there is success
});
}
});
$("#edate").datepicker("setDate","+0");
$("#sdate").datepicker("setDate","-7");
Upvotes: 0