This is an extension to the code example posted above. My form is used
to filter a table of results, so the form is loaded again after the
form has been submitted and it remembers the previous user input. So
if someone changes the dates then submits the form the datePickers
will need different minDate and maxDate settings respecting these new
dates.

Sorry if this code is confusing, but it does the job.

// [ JS ]
$(document).ready
(
        function()
        {
                // Create date using values from jsMinDate and jsMaxDate hidden
fields
                var jsMinDate = new Date($('#jsMinDate').val());
                var jsMaxDate = new Date($('#jsMaxDate').val());

                // Set Default based on Notice Date and Last date of schedule
                $('#txtDateTo, #txtDateFrom').datepicker('option', 'minDate',
jsMinDate);
                $('#txtDateTo, #txtDateFrom').datepicker('option', 'maxDate',
jsMaxDate);

                // Create array from txtDateTo
                var txtDateTo = $('#txtDateTo').val().split('/', 3);

                if ((txtDateTo.length == 3) && (txtDateTo[0].length <= 2) &&
(txtDateTo[1].length <= 2) && (txtDateTo[2].length <= 4))
                {
                        var dateDateTo = new Date(txtDateTo[2], txtDateTo[1] - 
1, txtDateTo
[0]);

                        if (dateDateTo.toDateString() != 
jsMaxDate.toDateString())
                        {
                                // Set txtDateFrom maxDate to txtDateTo date if 
txtDateTo date
does not equal jsMaxDate date.
                                $('#txtDateFrom').datepicker('option', 
'maxDate', dateDateTo);
                        }
                }

                // Create array from txtDateFrom
                var txtDateFrom = $('#txtDateFrom').val().split('/', 3);

                if ((txtDateFrom.length == 3) && (txtDateFrom[0].length <= 2) &&
(txtDateFrom[1].length <= 2) && (txtDateFrom[2].length <= 4))
                {
                        var dateDateFrom = new Date(txtDateFrom[2], 
txtDateFrom[1] - 1,
txtDateFrom[0]);

                        if (dateDateFrom.toDateString() != 
jsMinDate.toDateString())
                        {
                                // Set txtDateTo minDate to txtDateFrom value 
if txtDateFrom date
does not equal jsMinDate date.
                                $('#txtDateTo').datepicker('option', 'minDate', 
dateDateFrom);
                        }
                }
        }
);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to