let persons = document.querySelectorAll(".counter-block-input")[0],
restDays = document.querySelectorAll(".counter-block-input")[1],
place = document.getElementById("select"),
totalValue = document.getElementById("total"),
personsSum = 0,
daysSum = 0,
total = 0;
totalValue.textContent = 0;
persons.addEventListener("change", function() {
personsSum = +this.value;
total = (daysSum + personsSum) * 4000;
if (restDays.value == "") {
totalValue.textContent = 0;
} else {
totalValue.textContent = total;
}
});
restDays.addEventListener("change", function() {
daysSum = +this.value;
total = (daysSum + personsSum) * 4000;
if (persons.value == "") {
totalValue.textContent = 0;
} else {
totalValue.textContent = total;
}
});
place.addEventListener("change", function() {
if (restDays.value == "" || persons.value == "") {
totalValue.textContent = 0;
} else {
let a = total;
totalValue.textContent = a * this.options[this.selectedIndex].value;
}
});
persons.addEventListener("change", function() {
if (restDays.value == "" || restDays.value == 0 || persons.value == "" || persons.value == 0) {
totalValue.textContent = 0;
}
});
restDays.addEventListener("change", function() {
if (restDays.value == "" || restDays.value == 0 || persons.value == "" || persons.value == 0) {
totalValue.textContent = 0;
}
});
});
const persons = document.querySelectorAll(".counter-block-input")[0];
const restDays = document.querySelectorAll(".counter-block-input")[1];
const place = document.getElementById("select");
const totalValue = document.getElementById("total");
function calculateTotal() {
const personsSum = +persons.value || 0;
const daysSum = +restDays.value || 0;
const placeIndex = place.selectedIndex;
const total = (daysSum + personsSum) * place.options[placeIndex].value * 4000;
totalValue.textContent = total;
}
persons.addEventListener("change", calculateTotal);
restDays.addEventListener("change", calculateTotal);
place.addEventListener("change", calculateTotal);
calculateTotal(); // сразу вызываем, чтобы обнулить поле
if (persons.value == "") {
totalValue.textContent = 0;
} else {
totalValue.textContent = total;
}
persons.addEventListener("change", function() {
if (restDays.value == "" || restDays.value == 0 || persons.value == "" || persons.value == 0) {
totalValue.textContent = 0;
}
});