I want to remove datepicker function depending on the dropdownlist selected value. I try the following codes, but it still shows the calendar when I put the cursor in the text box. Please give me a suggestion.
$("#ddlSearchType").change(function () { if ($(this).val() == "Required Date" || $(this).val() == "Submitted Date") { $("#txtSearch").datepicker(); } else { $("#txtSearch").datepicker("option", "disabled", true); } });
To destroy a datepicker in jQuery UI, we will be using destroy() method. jQuery UI destroy() method is used to remove the complete functionality of the datepicker(). Parameters: This method does not accept any parameters. Return values: This method simply returns the datepicker to its pre-initial state.
You can try the enable/disable methods instead of using the option method: $("#txtSearch"). datepicker("enable"); $("#txtSearch"). datepicker("disable");
I would do it like this: $('#sv_pickup_date'). datepicker('destroy'). datepicker({ format: 'dd/mm/yyyy' , autoclose: true , startDate: '20/08/2018' , endDate: '24/08/2018' });
You can try the enable/disable methods instead of using the option method:
$("#txtSearch").datepicker("enable"); $("#txtSearch").datepicker("disable");
This disables the entire textbox. So may be you can use datepicker.destroy()
instead:
$(document).ready(function() { $("#ddlSearchType").change(function() { if ($(this).val() == "Required Date" || $(this).val() == "Submitted Date") { $("#txtSearch").datepicker(); } else { $("#txtSearch").datepicker("destroy"); } }).change(); });
Demo here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With