How to Pass variable from variables from one function to another in JQuery

Viewed 57

I have this code in view blade using JQuery to pass variables received from JSON:

view

< script type = "text/javascript" >
  var holidayDays = [];
var weekendInclusives;
var holidayInclusives;
$(document).ready(function() {
  $(document).on('change', '#leave_type', function() {
    var air_id = $(this).val();

    var a = $(this).parent();
    $('#weekendinclusive').val('');
    $('#holidayinclusive').val('');
    $('#leave_days').val('');
    $('#resumption_date').val('');
    // console.log("Its Change !");

    var op = "";

    $.ajax({
      type: 'get',
      url: '{{ route('
      get.leavecounts.all ') }}',
      data: {
        'id': air_id
      },
      dataType: 'json', //return data will be json
      // console.log("Its Change !");
      success: function(data) {
        $('#authorized_leave_days').val(data.authorizedleavedays);
        $('#available_leave_daysx').val(data.availableleavedays);
        $('#weekendinclusive').val(data.weekendinclusive);
        $('#holidayinclusive').val(data.holidayinclusive);
        holidayDays = data.nationalholidays;
        weekendInclusives = parseInt($("#weekendinclusive").val());
        holidayInclusives = parseInt($("#holidayinclusive").val());
      },
      error: function() {

      }
    });
  });
}); <
/script>
<input type="hidden" id="weekendinclusive" class="form-control" value="0">
<input type="hidden" id="holidayinclusive" class="form-control" value="0">

I want to pass the values of weekendInclusives and holidayInclusives to the if statement in the function below, but I found out that it's not being implemented:

< script type = "text/javascript" >
  $(document).ready(function() {
    function disabledays(date) {
      var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
      //if u have to disable a list of day
      var removeDays = holidayDays;
      if ($.inArray(ymd, removeDays) >= 0) {
        return [false];
      } else {
        //Show accept sundays
        var day = date.getDay();
        return [(day == 1 || day == 2 || day == 3 || day == 4 || day == 5)];
      }
    }

    function noWeekendsAndHolidays(date) {
      var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
      //if u have to disable a list of day
      var removeDays = holidayDays;
      if ($.inArray(ymd, removeDays) >= 0) {
        return [false];
      } else {
        //Show accept sundays
        var day = date.getDay();
        return [(day == 1 || day == 2 || day == 3 || day == 4 || day == 5)];
      }
    }

    function noHolidays(date) {
      var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
      //if u have to disable a list of day
      var removeDays = holidayDays;
      if ($.inArray(ymd, removeDays) >= 0) {
        return [false];
      }
    }

    let dateOpts = {
      dateFormat: 'dd-mm-yy',
      changeMonth: true,
      changeYear: true,
      showAnim: 'slideDown',
      duration: 'fast',
      minDate: 1,
      setDate: new Date(),
      yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
    };

    if (weekendInclusives == 0 && holidayInclusives == 0) {
      dateOpts.beforeShowDay = noWeekendsAndHolidays;
    } else if (weekendInclusives == 0 && holidayInclusives == 1) {
      dateOpts.beforeShowDay = noHolidays;
    } else if (weekendInclusives == 1 && holidayInclusives == 0) {
      dateOpts.beforeShowDay = $.datepicker.noWeekends;
    }

    $('.commencement_date').datepicker(dateOpts).datepicker('setDate', '1');
  }); <
/script>

How do I achieve this and ensure that it is being implemented?

Thanks

0 Answers
Related