user3616336
user3616336

Reputation: 39

JQUERY Datepicker week and year

I need the datepicker to add the week and year to the url, i currently have it working for the week but i'm unsure how to add a second parameter for the year.

I need it displayed like this: ?week=10&year=2019

Any help is greatly appreciated.

    $(function () {
    $("#datepicker").datepicker({
        onSelect: function(dateText, inst) {
          inst.input.val($.datepicker.iso8601Week(new Date(dateText)));
          window.open(window.location.pathname + '?week=' + this.value, "_self");
        }
    });
});

Upvotes: 0

Views: 241

Answers (1)

Negi Rox
Negi Rox

Reputation: 3922

you can use getFullYear() function of Date

$( function() {
     $("#datepicker").datepicker({
        onSelect: function(dateText, inst) {
          inst.input.val($.datepicker.iso8601Week(new Date(dateText)));
          var year=new Date(dateText).getFullYear();
          alert(window.location.pathname + '?week=' + this.value +"&year="+year)
           window.open(window.location.pathname + '?week=' + this.value +"&year="+year + this.value, "_self");
        }
    });
  } );
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
 
<p>Date: <input type="text" id="datepicker"></p>
 
 
</body>
</html>

Upvotes: 1

Related Questions