Change Datepicker minDate onClick

Change Datepicker minDate onClick

Hi there,

I am looking for a way to change the minDate of my datepicker onClick. I have two buttons, one needs to set the minDate to 0 and the other one to 1.

When the user then clicks the datepicker input field, the calender shows with the specific mindate.
So far I have below code, but the onClick does not change the minDate. What am I missing?

Thanks for the replies!


  1. $(function () 
  2. {
  3.     $("#datepicker").datepicker({
  4.         dateFormat: "M dd, yy"
  5.     });

  6. });

  7. $('#testXX').click(function () 
  8. {
  9.     $("#inputfield").val('15');
  10.     $('#datepicker').datepicker('option', 'minDate', new Date()+$('#inputfield').val());

  11. });