Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar change URL on select with jQuery UI datepicker

I am using jQuery UI picker and I am wondering if it's possible when someone pick a date, it automatically redirect them to the URL like so:

index.php?date=2013-10-15

Here's the plug-in I am using.

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

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

like image 791
John Guan Avatar asked Dec 07 '22 05:12

John Guan


1 Answers

1) What you need is window.location.href, which is the used to redirect the page. You can customize way the window to opened.

2) Once you select the date in datepicker (onSelect), you can combine the change event as @T.J. 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;
    });
like image 132
Praveen Avatar answered Dec 30 '22 11:12

Praveen