Behavior for #datepicker onselect not working i have a datepicker in a webform. I want to be notified when a date is selected in the datepicker. In my form template i drupal_add_js a js starting with :

Drupal.behaviors.booking_form_tma = {
    attach: function (context, settings) {
        for (var id in Drupal.settings.date_popup) {
            alert('found');
            var datepicker_settings = Drupal.settings.date_popup[id].settings;
            datepicker_settings.onSelect = function(dataText) {
                alert('selected: ' + dataText);
            };
            $('#' + id).datepicker(datepicker_settings);
        }
    }
};


The behavior attach code gets called only once, after the page gets loaded and never reach the alert: i guess the datepicker is not present in the div at this time. When the datepicker icon is clicked, the datepicker gets injected in a div but the behavior is not called and so nothing happen. None of the alert in the code above are shown.

Why doesn't it work?
jQuery(document).ready(function() {
    jQuery(".datepicker").datepicker({
        showOn: "button",
        buttonImage: "/images/calander.png",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        maxDate:'0',
        onSelect: function (selectedDateTime){
                //alert("here");
            } 
    });
 });


you can also write above code in js file