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

1.6k views Asked by At

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);        
  }
});
1

There are 1 answers

0
Yogesh On BEST ANSWER
var myVar;
jQuery(function(){  
         myVar = 'xzy';
    }); 

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