Mam problem, chcę wysłać formularz, gdy obszar tekstowy ma minimalną długość 20 znaków, ale mój kod nie działa. Cały czas po naciśnięciu przycisku zwracana jest wartość false Chcę, aby ten kod nie poszedł po załadowaniu okna i długości pola tekstowego, równej 0
const message = document.querySelector('#message');
const btn = document.querySelector('.btn');
f = false;
t = true;
const blockBtn = (b) => {
btn.addEventListener('click', e => {
console.log(b);
e.returnValue = b;
// console.log(e.returnValue);
});
}
const textArea = function (event) {
const length = this.value.length;
console.log(length);
if (length < 20 || length == null) {
blockBtn(f);
} else {
console.log('dziala')
blockBtn(t);
};
}
const textAreaWindow = () => {
const messageValueLength = message.value.length;
if (messageValueLength == 0) {
blockBtn(f);
}
}
message.addEventListener('input', textArea);
window.addEventListener('load', textAreaWindow);