jqueryfunctionvariablesonselect

How can I pass a variable into a Date picker onSelect function


Basically what I would like to accomplish is having a variable value inside the onSelect function. This value will be set in the Dom ready function. I need this variable to execute a function called checkDates everytime there is a change in the date picker.

jQuery(function(){  
  var myVar = 'xzy';
}); 

$("#PeriodStartDate").datepicker({            
  onSelect: function(dateText) {          
    console.log(myVar);
    checkDates(this.value, $('#EffectiveStartDate').val(), myVar);        
  }
});

Solution

  • var myVar;
    jQuery(function(){  
             myVar = 'xzy';
        }); 
    
    $("#PeriodStartDate").datepicker({            
            onSelect: function(dateText) {          
                console.log(myVar);
                checkDates(this.value,$('#EffectiveStartDate').val(),myVar);        
            }
        });