Jquery datepicker : changing the min and max date recursively
Hello All,
I am trying to add multiple date pickers on the dynamically generated rows . It works fine if its just adding a row and selecting from and to date . But say for example if i have added all the rows i need and change either from date or to date, i would like to change the min and max dates recursively. My problem it doesn't seem to recognize the on change event in the function below
Below is the code.
- $.datepicker.setDefaults({
- defaultDate: '+2w',
- changeMonth: true,
- showOtherMonths: true,
- selectOtherMonths: true,
- changeYear: true,
- dateFormat: 'dd-mm-yy',
- numberOfMonths: 1,
- minDate: 0
- });
- initDatepickers($('#t1'),0);
- function initDatepickers(row, minDate)
- {
-
- row.find('.fromdate,.todate').datepicker({
- minDate:minDate,
- onSelect: function(selectedDate) {
- if ($(this).hasClass('fromdate')) {
- var tdate=$(this).parent().parent().find('.todate').attr('id');
- $('#'+tdate).datepicker('option', 'minDate', selectedDate);
-
-
- } else {
-
- var fdate=$(this).parent().parent().find('.fromdate').attr('id');
- $('#'+fdate).datepicker('option', 'maxDate', selectedDate);
-
- }
- }}).on("change", function(dt) {
-
- if ($(this).hasClass('fromdate')) {
-
- $('.todate').datepicker({minDate: dt.target.value});
- }
- else {
-
- $('.fromdate').datepicker({minDate: dt.target.value});
- }
- });
- }
I would really appreciate any help on this.
Many Thanks,