Jquery ui Datepicker maxDate dynamically

Good morning, I would like to dynamically control the maxDate of my datpike. For example: I have a date in my form in a text box with a value of 20/12/12.

I tried this, but did not work, the calendar disables maxDate from the date I received in my text box. Could you help me with this:

$(function() { var date = new Date(); var m = date.getMonth(), d = date.getDate(), y = date.getFullYear(); $("#Panel2nrFecha").datepicker({ minDate: new Date(y, m, d), maxDate: $("#Panel2nrTextBox1").val(), dateFormat: "dd/mm/y", defaultDate: "+1w", changeMonth: true, numberOfMonths: 3 }); }); 
+6
source share
3 answers

After you initialize your datepicker, you can change the maxDate parameter as follows:

 $("#Panel2nrFecha").datepicker('option', 'maxDate', $("#Panel2nrTextBox1").val() ); 
+12
source

Use the beforeShow attribute beforeShow to set the minimum and maximum dates as described in this jQuery UI Datepicker v3.4.3 tutorial Examples - Date Range Mark Grabansky and Kate Wood:

 $("#Panel2nrFecha").datetimepicker({ beforeShow: customRange, dateFormat: "dd/mm/y", defaultDate: "+1w", changeMonth: true, numberOfMonths: 3 }); function customRange(input) { return { minDate: (input.id == 'Panel2nrMinDateTextBox' ? $('#Panel2nrMinDateTextBox').datepicker('getDate') : null), maxDate: (input.id == 'Panel2nrMaxDateTextBox' ? $('#Panel2nrMaxDateTextBox').datepicker('getDate') : null) }; } 
+4
source

Without posting the HTML, I'm not sure if this will solve your problem, but you tried this:

 $(function() { var date = new Date(); $("#Panel2nrFecha").datepicker({ minDate: date, maxDate: new Date($("#Panel2nrTextBox1").val()), dateFormat: "dd/mm/y", defaultDate: "+1w", changeMonth: true, numberOfMonths: 3 }); }); 

Notice that I removed the variables y , m and d , and also added new Date() in the maxDate property of the maxDate parameter.

+1
source

All Articles