1

i have dropdown for selecting data type of data in a textbox. dropdown options are like integer, decimal,string,date.

everything is working fine except one thing that is am unable to get a datepicker to the text box when dropdown is selected to date.

tried something like but failed to achieve

$(function () {
            $(".date1").datepicker({
                changeMonth: true,
                changeYear: true,
                numberOfMonths: 1

            });
        });

$("#<%=ddlDataType.ClientID %>").change(function () {
            if ($('#<%=ddlDataType.ClientID %> option:selected').text().toLowerCase() == "date") {
                $("#<%=txtDefaultValue.ClientID%>").prop("class", "date1");
            }
            else {
                $("#<%=txtDefaultValue.ClientID%>").prop("class", "");
            }
        });

what is the possible way to achieve this.

2
  • Are you using jQueryUI for your datepickers? Commented Mar 17, 2015 at 13:25
  • yes am using jQueryUI. Commented Mar 17, 2015 at 14:07

2 Answers 2

1

If you want to remove it (keep it enable for other purpose) then you can use destroy method

$("#<%=txtDefaultValue.ClientID%>").datepicker("destroy");

else

You can set option enable and disable, on change event of ddlDataType drowndown list.

$("#<%=txtDefaultValue.ClientID%>").datepicker('enable');

$("#<%=txtDefaultValue.ClientID%>").datepicker('disable');

alternative you can also set options to enable disable datepicker

//To enable

$("#<%=txtDefaultValue.ClientID%>").datepicker( "option", "disabled", false );

//To disable

$("#<%=txtDefaultValue.ClientID%>").datepicker( "option", "disabled", true );
Sign up to request clarification or add additional context in comments.

1 Comment

destroy is completely destroying the datepicker as i don't want that to happen bcoz user can select again date at that time datepicker should appear. enable/disable is disabling textbox that should be never has to happen.
0

If you just want your datepicker to be shown or hidden, you can try this code (assuming you are using jQuery).

    if ($('#<%=ddlDataType.ClientID %> option:selected').text().toLowerCase() == "date") 
    {
              $(".date1").css("display", "block");
    }
    else {
              $(".date1").css("display", "none");
    }

1 Comment

i just wanted to disable datepicker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.