Тема: JS: Непонятная ошибка.
function AUTOCOMPLETE() {
let date = new Date(document.getElementById('DATE1').value);
let month = date.getMonth()+1;
let year = date.getFullYear();
let sdate = document.getElementById('DATE2');
let tdate = document.getElementById('DATE3');
if (month<10) {
sdate.value = 'year-0month-01'.replace('year', year-1).replace('month', month);
} else {sdate.value = 'year-month-01'.replace('year', year-1).replace('month', month);}
if (month<11) {
tdate.value = 'year-0month-31'.replace('year', year).replace('month', month-1);
} else {tdate.value = 'year-month-31'.replace('year', year).replace('month', month-1);}
if (month==1) {
month = 12;
tdate.value = 'year-month-31'.replace('year', year-1).replace('month', month);
}
}
Вот такая функция. Происходит нечто странное:
Если в DATE1 вводить месяцы: 03, 05, 07, 10, 12, то DATE3 капризничает и выдаёт ошибку. Например:
The specified value "2021-06-31" does not conform to the required format, "yyyy-MM-dd".
Скажите, пожалуйста, как исправить?