In my php-file, I want to use the jQuery Datepicker.
When my file loads, I create the Datepicker disabled.
Then, when a special field in my php-file (it is a
This works for me on toggling enable and disable datepicker of JQuery:
if (condition) {
$('#ElementID').datepicker(); //Enable datepicker
} else {
//Disable datepicker without the ability to enter any character on text input
$('#ElementID').datepicker('destroy');
$('#ElementID').attr('readonly', true); }
I don't know why but when I use enable/disable in datepicker options, it doesn't behave the way it should be. It only works after you enable and disable it, but once you disable it, it doesn't enable again after, so the code above works perfectly fine for me:
if (condition) {
$('#ElementID').datepicker('enable'); //Enable datepicker
} else {
//Disable datepicker but I cannot enable it again once it goes through this condition
$('#ElementID').datepicker('disable'); }