Saturday, November 28, 2009

After worked with Jquery and their related plug ins in the web applications thought of writing nice posts on rare findings.

In some requirements we need to attach and remove the datepicker to a control or to a division. So, how to attach datepicker to a control or div dynamically… After read the jquery datepicker documentation, got to know the way to do that. The same case with Remove, enable, disable… So, below are the ways to do them.

Attach:
$(".datepicker").datepicker();

Remove:
$(".datepicker").datepicker("destroy");

Enable:
$(".datepicker").datepicker('enable');

Disable:
$(".datepicker").datepicker('disable');

NOTE: The selector I used [.datepicker] is just for example…. You need to give the id or class selector according to your requirement in place….

Do you like this post? Do you want to know anything more? Please post all here….


Categories: ,

7 comments:

  1. Very nice. It helped me a lot. Thank you!
    Carlos Perri.

    ReplyDelete
  2. Very nice. It helped a lot.
    Thank you.

    Carlos.

    ReplyDelete
  3. $(".datepicker").datepicker('disable'); does not work when called in document ready function like the following:
    $(function () {
    $(".datepicker").datepicker('disable');
    });

    But if I call the same code on a button click, it works!!! Weird!

    ReplyDelete
  4. Seems like your datepicker control is not initialized correctly by the time $(document).ready() is called. Please check once.

    ReplyDelete
  5. suppose I'm using the date picker on a c# asp.net webpage.

    I want the datepicker to start out disabled then enable it when a particular .net radio button is clicked on the webpage. I tried dropping the code you have in my code-behind and it dosent seem to like it. I'm asuming your code was indended for the html side?

    ReplyDelete
  6. Thank you, I needed this!

    ReplyDelete
  7. thank you, you save my time!

    ReplyDelete