javascript - ToDate Should not be Less than FromDate -
i have 2 datepicker 1 fromdate , second todate. want todate should not less fromdate. have tried solve not able solve properly.
$(document).on('focus', '.datepicker', function() { // alert(); $(this).datepicker({ format: "mm/dd/yyyy", //startdate: '-90d', //enddate: '+0d', autoclose: true }); $(".datepickerinputto").change(function () { var fromdate = $(".datepickerinputfrom").val; var todate = $(".datepickerinputto").val; if (todate <= fromdate) { alert("end date should greater start date"); $(".datepickerinputto").val = ""; } }); });
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-zosebrlbnqzlpnkikedrpv7loy9c27hhq+xp8a4mxaq=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css"></script> <div class="col-md-3"> <input type="text" placeholder="select date" class="form-control form-control-inline input-medium datepicker datepickerinputfrom"> </div> <div class="col-md-3"> <input type="text" placeholder="select date" class="form-control form-control-inline input-medium datepicker datepickerinputto"> </div>
you can changedate
, here can change todate
if fromdate
changed larger date value as:
$(document).ready(function () { $(".datepickerinputfrom").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()); $('.datepickerinputto').datepicker('setstartdate', mindate); $(".datepickerinputto").val($(".datepickerinputfrom").val()); $(this).datepicker('hide'); }); $(".datepickerinputto").datepicker({ format: 'dd/mm/yyyy', todayhighlight: true, enddate: new date() }).on('changedate', function (selected) { $(this).datepicker('hide'); }); });
Comments
Post a Comment