Datepicker show error

Datepicker show error

hi team.
I have two datepicker fields: Check-in "$(entr)" and Check-out "$(sal)".
If  I select next month on Check-in, the close function shows Check-out datepicker with next month, but if I go back to Check-in and select previous month, I need to double click to go to previous month in Check out’s field.
I find several examples but always see this error.

Any solution?


My code:


$(entr).datepicker({
                dateFormat: "dd/mm/yy",
                minDate: new Date(),
                firstDay: 1,
                showAnim: 'slideDown',
                onSelect: function(dateText, inst) {
                    // Cuando se modifica fecha de entrada, si no es igual o
                    // superior a la de salida, no hacemos nada. Si no,
                    // le añadimos una noche
                    dateText = dateText.split('/');
                    var entrada = new Date(dateText[2], (dateText[1]-1), dateText[0]);
                    var salida = $(sal).datepicker('getDate');
                    $(sal).datepicker("option", "minDate", _sumar_noches($(entr).datepicker('getDate'),1));
                    if (entrada >= salida) {
                        // Colocaremos la fecha final como la inicial + a
                        // La fecha mínima de la fecha final también debe ser la inicial + 1
                        var manana = _sumar_noches(entrada, 1);
                        $(sal).val(_formatear_fecha(manana));
                        fechas2txt(_entrada);
                        fechas2txt(_salida);
                    } else {
                        fechas2txt(_entrada);
                    }
                    actualiza_noches(entrada, salida);
                },
                onClose: function(){
                    $(sal).datepicker('show');
                }
            });

            $(sal).datepicker({
                dateFormat: "dd/mm/yy",
                firstDay: 1,
                showAnim: 'slideDown',
                onSelect: function(dateText, inst) {
                    // Si la fecha de salida, es más pequeña que la fecha de
                    // entrada. No es válida
                    var entrada = $(entr).datepicker('getDate');
                    dateText = dateText.split('/');
                    var salida = new Date(dateText[2], (dateText[1]-1), dateText[0]);

                    if (salida <= entrada) {
                        var manana = _sumar_noches(entrada, 1);
                        $(sal).datepicker("option","minDate",_formatear_fecha(manana))
                        $(sal).val(_formatear_fecha(manana));
                        fechas2txt(_entrada);
                        fechas2txt(_salida);
                    } else {
                        fechas2txt(_salida);
                        $(_elementos).find('button').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
                    }
                    actualiza_noches(entrada, salida);
                    toggle_button();
                }
            });