Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use ajax post when datepicker change date?

Good afternoon

Value in input change with datepicker ui.

I want use ajax post when value in input will be change.

For this i use script:

<input type="text" name="date" class="datepicker" id="datepicker">

$(".datepicker").datepicker({changeYear: true});

$(".datepicker").on("change",function(){
var date=$(this).val();
$.post("test.php", {
date:date
},
function(data){$('#testdiv').html('');$('#testdiv').html(data);
});
});

But ajax post query is executed with the old date.

Datepicker does not have time change value in input.

Tell me how to do query after datepicker change the date in the field?

Me need:

1) datepicker change the date;

2) query should be send with new date.

like image 890
Leo Loki Avatar asked Feb 21 '13 05:02

Leo Loki


1 Answers

You can trigger ajax post on datepicker events:

$("#datepicker").datepicker({

    onSelect: function(date, instance) {

        $.ajax
        ({
              type: "Post",
              url: "www.example.com",
              data: "date="+date,
              success: function(result)
              {
                  //do something
              }
         });  
     }
});

Hope this helps- @Codebrain

like image 168
Sakthivel Avatar answered Oct 02 '22 04:10

Sakthivel