i’m tring to create a multiple login form , every was fine but i want to disable next button if the email input is empty.
the input class="email"
and the button class ="btn-next"
i will appreciate any help thanks.
<sub>const pageBox = document.querySelector('.page-box');
const btnNext = document.querySelector('.btn-next');
const btnBack = document.querySelector('.btn-back');
const checkboxPass = document.querySelector('.checkbox-pass');
const passwordInput = document.querySelector('.password');
const loginTitle = document.querySelector('.loginTitle-text');
const userEmail = document.querySelector('.user-email');
const emailInput = document.querySelector('.email');
btnNext.onclick = (e) => {
e.preventDefault();
pageBox.classList.add('active-pass');
setTimeout(() => passwordInput.focus(), 500);
loginTitle.innerHTML = 'Welcome';
userEmail.innerHTML = '' + emailInput.value;
};
btnBack.onclick = (e) =>{
e.preventDefault();
pageBox.classList.remove('active-pass');
loginTitle.innerHTML = 'Sign in';
userEmail.innerHTML = 'Please continue,';
emailInput.focus();
};
checkboxPass.onclick = () => {
if(checkboxPass.checked) {
passwordInput.type = 'text';
}
else{
passwordInput.type = 'password';
}
};
emailInput.addEventListener("btnNext", (e) => {
preventDefault();
btnNext.disabled()
if(emailInput.value.length > 0) {
btnNext.disabled = 'true';
}
else{
btnNext.disabled = 'false';
}
});
</sub>
2
Answers
Instead of your current code,
try to change to this code,
btnNext
event, useinput
(when the input is changed)disabled
attribute for the button based on the input’s value.Setting
disabled="false"
doesn’t work as explained here.