Calendar change URL when selected using jQuery UI datepicker

I am using jQuery UI picker, and I am wondering if it is possible, when someone selects a date, he automatically redirects them to the URL as follows:

index.php?date=2013-10-15

Here's the plugin I'm using.

<script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
</script>

Date: <input type="text" id="datepicker" />

+4
source share
3 answers

1) You need one that is used to redirect the page. You can customize how the window opens. window.location.href

2) After selecting a date in datepicker ( onSelect), you can combine the event changeas @TJ Crowder said in his answer.

You can try like this

$("#datepicker")
    .datepicker({
      dateFormat: "yy-mm-dd",
      onSelect: function(dateText) {
        $(this).change();
      }
    })
    .change(function() {
      window.location.href = "index.php?date=" + this.value;
    });
+12
source

Try the following:

$(function () {
    $("#datepicker").datepicker({
        dateFormat: "yy-mm-dd",
        onSelect: function () {
            window.open(document.URL + '?date=' + this.value);
        }
    });
});

+2

I hope this works according to your requirement.

  

Date of:

  
<script>
$(function() {
$( "#datepicker" ).datepicker();

});

function myFunc(){
    var dateData = $("#datepicker").val();

    if(dateData != '' ){

        var url = "http://www.index.php?date="+ dateData ;
        window.open(url);

    }
}


</script>

<body>
<p>Date: <input type="text" id="datepicker" onchange="myFunc();" /></p>
</body>
0
source

All Articles