radhwane
radhwane

Reputation: 21

Action to fill Date picker automatically

Image

Can anyone help me to setup an action to fill this datepicker automatically?

This is the source code

 $('.date_of_birth').datepicker({
    format: "yyyy-mm-dd",
    endDate: new Date(dtJS),
    startDate: '-100y',
    autoclose: true,
    startView: 2
 });

And which program can I use to setup this function?

Upvotes: 2

Views: 230

Answers (1)

Amal
Amal

Reputation: 3426

Try this code

adding minViewMode: "years" option help you to generate datepicker as shown in your image.

$(document).ready(function(){
  var dtJS="2017-06-28";
    $('.date_of_birth').datepicker({
    format: "yyyy",
    endDate: new Date(dtJS),
    startDate: '-100y',
    autoclose: true,
    minViewMode: "years",
    startView: 1
 });
});

$(document).ready(function(){
  var dtJS="2017-06-28";
    $('.date_of_birth').datepicker({
    format: "yyyy",
    endDate: new Date(dtJS),
    startDate: '-100y',
    autoclose: true,
    minViewMode: "years",
    startView: 1
 });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker3.min.css">
<input class="date_of_birth" type="text" />

Upvotes: 1

Related Questions