-1

I used this snippet to display dates using datepicker:

$(document).ready(function(){

    $("#txtFrom").datepicker({
      numberOfMonths: 1,
      onSelect: function (selected) {
        var dt = new Date(selected);
        dt.setDate(dt.getDate() + 1);
        $("#txtTo").datepicker("option", "minDate", dt);
      }
    });
    $("#txtTo").datepicker({
      numberOfMonths: 1,
      onSelect: function (selected) {
        var dt = new Date(selected);
        dt.setDate(dt.getDate() - 1);
        $("#txtFrom").datepicker("option", "maxDate", dt);
      }
    });

    $('#txtFrom').on("click", function(){
      alert($(this).getDate());
    });
});

Now I wanna be able to store each date in a variable and display and alert after choosing and clicking in the input submit button. Please help

Note: In the snippet I actually tried but it didn't work.

Hope you can help from the entire code here

Jason P
  • 26,984
  • 3
  • 31
  • 45
Ragmah
  • 413
  • 3
  • 12

2 Answers2

0

You can try on button click event:

$('#txtFrom').on("click", function(){
      alert($("#txtFrom").val());
      alert($("#txtTo").val());
 });
0

If you want as a Date Object use:

$('#txtFrom').datepicker( 'getDate' )
funcoding
  • 741
  • 6
  • 11