0

I have two datepickers 'startDate' and 'targetDate'.I want to set the minDate of the 'targetDate' as the value of 'startDate'.The following code is not working.ie,the minDate of 'targetDate' is not set.

$("#startDate").datepicker({ changeMonth : true, changeYear : true, dateFormat : "dd-M-yy", minDate : 0, showMonthAfterYear : true, onClose : function() { $(this).toggleClass('ui-state-focus'); } }); $("#targetDate").datepicker({ changeMonth : true, changeYear : true, dateFormat : "dd-M-yy", minDate : new Date($("#startDate").val()), showMonthAfterYear : true, onClose : function() { $(this).toggleClass('ui-state-focus'); } }); 
3
  • Where you are calling the function for targetDate ? Commented Aug 19, 2014 at 7:31
  • calling from this text box. <form:input path="targetDate" id="targetDate" /> Commented Aug 19, 2014 at 7:34
  • 1
    As per stackoverflow.com/questions/16267903/… - you need to change the minDate of the targetDate datepicker during the onClose event of the startDate datepicker. Commented Aug 19, 2014 at 7:38

1 Answer 1

1

You need to set min-date of targetDate in onSelect event of startDate

Called when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.

Use

$('#startDate').datepicker({ onSelect: function(selectedDate) { $('#targetDate').datepicker('option', 'minDate', selectedDate); } }); 

DEMO

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.