Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two textbox from and to which shows month and year picker. I want to set mindate(month) for to textbox from the value from textbox which user has selected.
Here is my jscript but its not working.


XML
$(function () {
    $("#<%=frm_txtdatefrm.ClientID %>").datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'M yy',
        showButtonPanel: true,
        onClose: function () {
            var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();

            var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();

            $(this).datepicker('setDate', new Date(iYear, iMonth, 1));
            $(this).datepicker('refresh');
        },

        beforeShow: function () {
            if ((selDate = $(this).val()).length > 0) {
                iYear = selDate.substring(selDate.length - 4, selDate.length);

                iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames'));

                $(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
                $(this).datepicker('setDate', new Date(iYear, iMonth, 1));
            }
            if ((selDate = $(this).val()).length > 0) {
                year = selectedDate.substring(selectedDate.length - 4, selectedDate.length);
                month = jQuery.inArray(selectedDate.substring(0, selectedDate.length - 5), $(this).datepicker('option', 'monthNamesShort'));
                $("#<%=frm_txtdateto.ClientID %>").datepicker("option", "mindate", new Date(year, month, 1));
            }
        }
    });

    $("#<%=frm_txtdatefrm.ClientID %>").focus(function () {
        $(".ui-datepicker-calendar").hide();
        $("#ui-datepicker-div").position({
            my: "center top",
            at: "center bottom",
            of: $(this)
        });
    });

    $("#<%=frm_txtdatefrm.ClientID %>").blur(function () {
        $(".ui-datepicker-calendar").hide();
    });
Posted
Updated 24-Sep-15 1:30am
v2

1 solution

Hi,

You need to set a value for the datepickers minDate property.

Have a look at the Documentation[^] for example usage.

... hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900