4

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" />

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
John Guan
  • 744
  • 2
  • 11
  • 26

3 Answers3

14

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;
    });
Community
  • 1
  • 1
Praveen
  • 55,303
  • 33
  • 133
  • 164
2

Try this:

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

Demo here

Sergio
  • 28,539
  • 11
  • 85
  • 132
0

I hope this will work out as per your requirement.

Date:

<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>