3

So I'm using http://amsul.ca/pickadate.js/ and I can't seem to figure out how to set a specific date into the date picker. (Date picker for pickadate.js v3.5.6, http://amsul.github.io/pickadate.js/date.htm).

For example if I say:

var today = '01-01-1983';
picker.val(today);

This will change the text inside the input, but when you open the picker the date has not been set to 1983.

So how do you use js/jquery to update the date in the date picker?

Donal.Lynch.Msc
  • 3,365
  • 12
  • 48
  • 78

4 Answers4

9
  //try this  
 var date = new Date(1983, 1, 1);
    var picker = $('#date_picker').pickadate('picker');
    picker.set('select', date);
waqas jamil
  • 423
  • 3
  • 9
  • I keep getting 'undefined'. I'm using the correct class and id. Any idea what could be wrong? Running the command from chrome console seems to work. But not on my page itself :/ – Enrico Apr 17 '20 at 08:27
3

Try to add the value like this:

<input data-value="2015/04/20">

madalinivascu
  • 32,064
  • 4
  • 39
  • 55
2

You should be able to set the correct date via something like this:

// year, month date
picker.set('view', [1983, 1, 1])

// JavaScript Date
picker.set('view', new Date(1983, 1, 1))

// UNIX timestamps.
picker.set('view', 412902000000)

// string and format option.
picker.set('view', '1983-01-01', { format: 'yyyy-mm-dd' })

Hope that helps

Guido Kitzing
  • 892
  • 5
  • 14
0
<script>
    $(document).ready(function () {
        $('#DateChanger').click(function() {
             $('#dateFrom').val("yyyy-mm-dd");
        });
    });
</script>
<input type="date" id="dateFrom" name="dtFrom" />
<button id="DateChanger">Click</button>
Shaddy
  • 212
  • 1
  • 3
  • 22