salve a tutti sono nuovo e non tanto esperto nel programmare, ho un problema con le funzioni di java script nel foglio di java script vado a inserire le varie "let" andando poi a eseguire una funzione termino il tutto inserisco altre let e un'altra funzione, il problema e' che esegue solo il primo blocco, o meglio se scrivo in cima let1 funzione 1 e poi let2 funzione2 mi esegue solo il blocco1 se sposto il blocco2 prima del blocco1 mi esegue solo il blocco2, quindi penso che il codice e' scritto in forma corretta ma non capisco perche' vanno in conflitto. Spero che qualcuno mi aiuti perche ho un test da superare.
//blocco1
let inputName = document.querySelector(".input");
let inputLastName = document.querySelector(".input2");
let inputEmail = document.querySelector(".input3");
let inputComment = document.querySelector(".comment");
let button = document.querySelector(".submit");
inputName.addEventListener("change", buttonable);
inputLastName.addEventListener("change", buttonable);
inputEmail.addEventListener("change", buttonable);
inputComment.addEventListener("change", buttonable);
function buttonable() {
if((document.querySelector('.input').value === "") ||
(document.querySelector('.input2').value === "") ||
(document.querySelector('.input3').value === "") ||
(document.querySelector('.comment').value === "")) {
button.disabled = true;
}else {
button.disabled = false;
}
};
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
let form = document.querySelector('form').elements;
console.log("Name: ", form['Name'].value);
console.log("Last Name: ", form['LastName'].
value);
console.log("Email: ", form['Email'].value);
console.log("Comment: ", form['comment'].value);
});
//fine blocco1
//blocco2
let prevBtn = document.querySelector('.prev');
let nextBtn = document.querySelector('.next');
let map = document.querySelectorAll('.map');
let currentlySelected = 0;
prevBtn.addEventListener('click', function(){
map[currentlySelected].classList.remove("active");
currentlySelected--;
map[currentlySelected].classList.add("active");
nextBtn.hidden = false;
if (currentlySelected === 0) {
prevBtn.hidden = true;
}
});
nextBtn.addEventListener('click', function(){
map[currentlySelected].classList.remove("active");
currentlySelected++;
map[currentlySelected].classList.add("active");
prevBtn.hidden = false;
if (map.length === currentlySelected + 1) {
nextBtn.hidden = true;
}
});
//fine blocco2
//blocco1
let inputName = document.querySelector(".input");
let inputLastName = document.querySelector(".input2");
let inputEmail = document.querySelector(".input3");
let inputComment = document.querySelector(".comment");
let button = document.querySelector(".submit");
inputName.addEventListener("change", buttonable);
inputLastName.addEventListener("change", buttonable);
inputEmail.addEventListener("change", buttonable);
inputComment.addEventListener("change", buttonable);
function buttonable() {
if((document.querySelector('.input').value === "") ||
(document.querySelector('.input2').value === "") ||
(document.querySelector('.input3').value === "") ||
(document.querySelector('.comment').value === "")) {
button.disabled = true;
}else {
button.disabled = false;
}
};
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
let form = document.querySelector('form').elements;
console.log("Name: ", form['Name'].value);
console.log("Last Name: ", form['LastName'].
value);
console.log("Email: ", form['Email'].value);
console.log("Comment: ", form['comment'].value);
});
//fine blocco1
//blocco2
let prevBtn = document.querySelector('.prev');
let nextBtn = document.querySelector('.next');
let map = document.querySelectorAll('.map');
let currentlySelected = 0;
prevBtn.addEventListener('click', function(){
map[currentlySelected].classList.remove("active");
currentlySelected--;
map[currentlySelected].classList.add("active");
nextBtn.hidden = false;
if (currentlySelected === 0) {
prevBtn.hidden = true;
}
});
nextBtn.addEventListener('click', function(){
map[currentlySelected].classList.remove("active");
currentlySelected++;
map[currentlySelected].classList.add("active");
prevBtn.hidden = false;
if (map.length === currentlySelected + 1) {
nextBtn.hidden = true;
}
});
//fine blocco2