javascript - Create dependent datepickers using bootstrap-datepicker -


i need create 2 date pickers using datepicker https://github.com/uxsolutions/bootstrap-datepicker date selected in first datepicker used start date of second. dates before date picker of first 1 disabled in second.

the html first date-picker:

 <div class="col-sm-6 row-margin" id="div-last-day">  <div class="input-group date">  <input type="text" class="test-width form-control input-xs" name="last-day-worked" id="last-day" placeholder="select last date" readonly><span class="input-group-addon input-xs"><i class="glyphicon glyphicon-calendar"></i></span> 

second date-picker:

  <div class="col-sm-6 row-margin" id="div-separation-day">      <div class="input-group date">       <input type="text" class="test-width form-control input-xs" name="separation-day-worked" id="separation-day" placeholder="select separation date" readonly><span class="input-group-addon input-xs"><i class="glyphicon glyphicon-calendar"></i></span>  </div>   </div> 

here of code:

$("#div-last-day .input-group.date").datepicker({             format: "dd-m-yyyy",             todayhighlight: true,             autoclose: true,         });         $('#div-last-day .input-group.date').datepicker()         .on('changedate', function (e) {             var lastdate = $('#div-last-day .input-group.date').datepicker('getdate');             var date = new date(lastdate);             var curr_date = date.getdate();             var curr_month = date.getmonth();             var curr_year = date.getfullyear();             perfect_date = curr_date + "-" + m_names[curr_month]             + "-" + curr_year;             $("#div-separation-day .input-group.date").datepicker({                 format: "dd-m-yyyy",                 todayhighlight: true,                 startdate: perfect_date,                 autoclose: true,             });         }); 

here fiddle working on https://jsfiddle.net/5tpn12l8/

the fiddle works first time when change date in first date-picker doesn't update second date-picker.

you can below:

html:

<input class="form-control"  id="txtfromdate" /> <input class="form-control" id="txttodate" /> 

jquery:

$(document).ready(function () {     $("#txtfromdate").datepicker({         format: 'dd/mm/yyyy',         autoclose: 1,         //startdate: new date(),         todayhighlight: false,         //enddate: new date()     }).on('changedate', function (selected) {         var mindate = new date(selected.date.valueof());         $('#txttodate').datepicker('setstartdate', mindate);         $("#txttodate").val($("#txtfromdate").val());         $(this).datepicker('hide');     });      $("#txttodate").datepicker({         format: 'dd/mm/yyyy',         todayhighlight: true,         //enddate: new date()     }).on('changedate', function (selected) {         $(this).datepicker('hide');     }); }); 

jsfiddle demo


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -