DatePicker not working after a first call

DatePicker not working after a first call

Hi to all of you,
I inserted two datepickers in my webpage, followed by a Submit button.
The problem is that they work only for the first time, then if you click on any of the datepickers, no calendar is shown below.

Simply the program doesn't enter in the function defined for onSelect.

This is the code of the Datepickers:

    $(document).ready(function(){
        var dates = $('#from, #to').datepicker({
            dateFormat: 'yy-mm-dd',
            changeMonth: true,
            changeYear: true,
            minDate: '2000-01-01',
            maxDate: '+0d',
            onSelect: function(selectedDate) { // Make currentDate in "to" datepicker start from selected date in "from" datepicker ??
                var option = this.id == "from" ? "minDate" : "maxDate";
                var instance = $(this).data("datepicker");
                var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                dates.not(this).datepicker("option", option, date);
            }
        });
    });


And this is the button:
<input value="Submit" type="submit" onclick="MyFunction(); return false;">


I'm not expert in AJAX or similar things, maybe I'm doing something trivially wrong.. I was thinking about the "context": the function which I call (MyFunction()) calls an other function itself.

Do you have some suggestion?
Thanks for reading.

Piero