Fehler: uncaught exception: Missing instance data for this datepicker

Fehler: uncaught exception: Missing instance data for this datepicker

Hi there,

i'am using the datepicker from the jquery ui framework and getting this error when i use the actually outcommented line on a page where no datepicker is present. Is the way i'am setting the initial minDate in my #datepickerTo wrong or no good programming-style?

I don't want to make inline or seperate JS-Files for different pages. Is there a way to fix this or use should i use another method? Thanks in advance for responses.
  1. $("#datepickerTo").datepicker({
       dateFormat: 'dd.mm.yy',
    });
           
    $("#datepickerFrom").datepicker({
       dateFormat: 'dd.mm.yy',
       onClose: function(dateText, inst){
         $("#datepickerTo").datepicker("option","minDate", $("#datepickerFrom").datepicker("getDate"));
       }
    });       
           
    //$("#datepickerTo").datepicker("option","minDate", $("#datepickerFrom").datepicker("getDate"));