0

I want to disable all Mondays in my jQuery calendar and I am using this code :

function DisableMonday(date) {
   alert(date);
   var day = date.getDay();
   if (day == 1) {
      return [false] ; 
   } 
   else {  
       return [true] ;
   }
}

jQuery(document).ready(function(){
   alert('test');
   jQuery('.datepicker').datepicker({                   
       beforeShowDay: DisableMonday()

   }); 
});

my problem seems to be that (date) variable in DisableMonday() function is undefined...how can I solve this problem

1
  • You are calling the function without a value, and passing its return value for beforeShowDay. Instead, you should be passing the function itself (i.e. beforeShowDay: DisableMonday) Commented Aug 2, 2015 at 11:04

2 Answers 2

1

Have you tried this? Without using a separate method

$(".datepicker").datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day != 1)];
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

According to jQueryUI's Datepicker API,

enter image description here


Just remove the parenthesis () after your DisableMonday function :

Replace :

jQuery('.datepicker').datepicker({                   
    beforeShowDay: DisableMonday()
}); 

By :

jQuery('.datepicker').datepicker({                   
    beforeShowDay: DisableMonday
}); 

And it will work, take a look at Working fiddle.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.