0

I've got simple date picker based on mootools (http://www.monkeyphysics.com/mootools/script/2/datepicker) This is not jQuery datepicker, it's event triggers don't work.

I'd need to calculate days and other things once dates are picked, calculation works fine, I need it to fire after user decides to change dates, I've tried all event handlers I could find, they all work if you press enter or click another field, but it should recalculate right after clicking (picking) the date.

<input type="text" name="arrival" value="2016-10-05" title="" class="fromdate">
<input type="text" name="departure" value="2016-10-08" title="" class="todate">
<input type="text" name="addnight" value="" title="" class="calculated">

<script type="text/javascript">
  $("select, input, .datepicker_dashboard").on("change paste keyup blur click mouseup hover focus focusout", function() {

   var calculus = daydiff(parseDate($('.fromdate').val()), parseDate($('.todate').val()));
if (calculus<0) {var calculus=0;}
$(".calculated").val(calculus);

}
</script>
Kyuzo
  • 39
  • 1
  • 1
  • 9
  • may be you are looking for below link [JQuery Datepicker onchange event help!](http://stackoverflow.com/questions/6471959/jquery-datepicker-onchange-event-help) – Dhaval Pankhaniya Apr 18 '16 at 12:19
  • this one works like I want it to, but mine is not JQuery Datepicker – Kyuzo Apr 18 '16 at 12:32

2 Answers2

2

Reading the documentation (linked by yourself) tells me that you are able to set an onSelect handler in the options while creating the datepicker with new DatePicker(input-target-selector [, options-object]);

onSelect
Event hook triggered when a date is selected. (v1.16+: comes with 1 argument, a standard javascript Date object representing the selected Date)

Fidel90
  • 1,828
  • 6
  • 27
  • 63
0

Try this. I got the answer from the link listed below Trigger function when date is selected with jQuery UI datepicker

  $("#dt").datepicker({
  onSelect: function(dateText, inst) {
    var date = $(this).val();
    var time = $('#time').val();
    alert('on select triggered');
    $("#start").val(date + time.toString('              HH:mm').toString());

  }
  });
Community
  • 1
  • 1
LearningPhase
  • 1,277
  • 1
  • 11
  • 20