Please complete a separate registration form for each child.
let weekOne = Array.from(document.getElementsByName(“week-1[]”));
let weekTwo = Array.from(document.getElementsByName(“week-2[]”));
let weekThree = Array.from(document.getElementsByName(“week-3[]”));
let weekFour = Array.from(document.getElementsByName(“week-4[]”));
// let weekTwo = Array.from(document.getElementsByName(“week-2[]”));
// let weekThree = Array.from(document.getElementsByName(“week-3[]”));
const numberWeeks = document.getElementById(“number-weeks”);
const rateWeeks = document.getElementById(“rate-week”);
const weeksPrice = document.getElementById(“week-price”);
const numberDays = document.getElementById(“number-days”);
const rateDays = document.getElementById(“rate-days”);
const daysPrice = document.getElementById(“day-price”);
const numberEarlyMornings = document.getElementById(“number-early-mornings”);
const rateEarlyMornings = document.getElementById(“rate-early-morning”);
const earlyMorningsPrice = document.getElementById(“early-morning-price”);
const numberLateAfternoons = document.getElementById(“number-late-afternoons”);
const rateLateAfternoons = document.getElementById(“rate-late-afternoon”);
const lateAfternoonsPrice = document.getElementById(“late-afternoon-price”);
const siblingDiscountCheckbox = document.getElementsByName(“sibling-discount[]”);
const siblingDiscount = document.getElementById(“sibling-discount”);
const totalPrice = document.getElementById(“total-price”);
let numberDaysWeekOne = 0;
let numberDaysWeekTwo = 0;
let numberDaysWeekThree = 0;
let numberDaysWeekFour = 0;
let discountRatio = 1;
function getPrice(price, number, rate) {
price.value = “£” + (number.value * rate.value);
}
function getRatio() {
if (siblingDiscountCheckbox[0].checked == true) {
return discountRatio = 0.9;
} else if (siblingDiscountCheckbox[0].checked == false) {
return discountRatio = 1;
}
}
function getTotalPrice() {
getRatio();
totalPrice.value = “£” + (Math.round(discountRatio * ((numberWeeks.value * rateWeeks.value) + (numberDays.value * rateDays.value) + (numberEarlyMornings.value * rateEarlyMornings.value) + (numberLateAfternoons.value * rateLateAfternoons.value)) * 100) / 100);
}
numberWeeks.addEventListener(‘change’, (event) => {
getPrice(weeksPrice, numberWeeks, rateWeeks);
getTotalPrice();
});
numberDays.addEventListener(‘change’, (event) => {
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
});
numberEarlyMornings.addEventListener(‘change’, (event) => {
getPrice(earlyMorningsPrice, numberEarlyMornings, rateEarlyMornings);
getTotalPrice();
});
numberLateAfternoons.addEventListener(‘change’, (event) => {
getPrice(lateAfternoonsPrice, numberLateAfternoons, rateLateAfternoons);
getTotalPrice();
});
siblingDiscount.addEventListener(‘change’, (event) => {
getTotalPrice();
});
weekOne.forEach((item, index) => {
item.addEventListener(‘change’, (event) => {
if (weekOne[index].value == “Whole week”) {
if (weekOne[index].checked == true) {
numberWeeks.value = numberWeeks.valueAsNumber += 1;
weekOne.map(x => {
for (i = 1; i < weekOne.length; i++) {
weekOne[i].disabled = true;
weekOne[i].checked = true;
}
})
} else if (weekOne[index].checked == false) {
numberWeeks.value = numberWeeks.valueAsNumber -= 1;
weekOne.map(x => {
for (i = 1; i < weekOne.length; i++) {
weekOne[i].disabled = false;
weekOne[i].checked = false;
}
})
numberDaysWeekOne = 0;
}
if (numberDays.valueAsNumber - numberDaysWeekOne > 0) {
numberDays.valueAsNumber -= numberDaysWeekOne;
} else if (numberDays.valueAsNumber – numberDaysWeekOne <= 0) {
numberDays.valueAsNumber = numberDaysWeekThree + numberDaysWeekTwo + numberDaysWeekFour;
}
getPrice(weeksPrice, numberWeeks, rateWeeks);
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
} else if (weekOne[index].value != "Whole week") {
if (weekOne[index].checked == true) {
numberDays.value = numberDays.valueAsNumber += 1
numberDaysWeekOne += 1;
} else if (weekOne[index].checked == false) {
numberDays.value = numberDays.valueAsNumber -= 1;
numberDaysWeekOne -= 1;
}
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
}
})
});
weekTwo.forEach((item, index) => {
item.addEventListener(‘change’, (event) => {
if (weekTwo[index].value == “Whole week”) {
if (weekTwo[index].checked == true) {
numberWeeks.value = numberWeeks.valueAsNumber += 1;
weekTwo.map(x => {
for (i = 1; i < weekTwo.length; i++) {
weekTwo[i].disabled = true;
weekTwo[i].checked = true;
}
})
} else if (weekTwo[index].checked == false) {
numberWeeks.value = numberWeeks.valueAsNumber -= 1;
weekTwo.map(x => {
for (i = 1; i < weekTwo.length; i++) {
weekTwo[i].disabled = false;
weekTwo[i].checked = false;
}
})
numberDaysWeekTwo= 0;
}
if (numberDays.valueAsNumber - numberDaysWeekTwo > 0) {
numberDays.valueAsNumber -= numberDaysWeekTwo;
} else if (numberDays.valueAsNumber – numberDaysWeekTwo <= 0) {
numberDays.valueAsNumber = numberDaysWeekOne + numberDaysWeekThree + numberDaysWeekFour;
}
getPrice(weeksPrice, numberWeeks, rateWeeks);
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
} else if (weekTwo[index].value != "Whole week") {
if (weekTwo[index].checked == true) {
numberDays.value = numberDays.valueAsNumber += 1
numberDaysWeekTwo += 1;
} else if (weekTwo[index].checked == false) {
numberDays.value = numberDays.valueAsNumber -= 1;
numberDaysWeekTwo -= 1;
}
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
}
})
});
weekThree.forEach((item, index) => {
item.addEventListener(‘change’, (event) => {
if (weekThree[index].value == “Whole week”) {
if (weekThree[index].checked == true) {
numberWeeks.value = numberWeeks.valueAsNumber += 1;
weekThree.map(x => {
for (i = 1; i < weekThree.length; i++) {
weekThree[i].disabled = true;
weekThree[i].checked = true;
}
})
} else if (weekThree[index].checked == false) {
numberWeeks.value = numberWeeks.valueAsNumber -= 1;
weekThree.map(x => {
for (i = 1; i < weekThree.length; i++) {
weekThree[i].disabled = false;
weekThree[i].checked = false;
}
})
numberDaysWeekThree= 0;
}
if (numberDays.valueAsNumber - numberDaysWeekThree > 0) {
numberDays.valueAsNumber -= numberDaysWeekThree;
} else if (numberDays.valueAsNumber – numberDaysWeekThree <= 0) {
numberDays.valueAsNumber = numberDaysWeekOne + numberDaysWeekTwo + numberDaysWeekFour;
}
getPrice(weeksPrice, numberWeeks, rateWeeks);
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
} else if (weekThree[index].value != "Whole week") {
if (weekThree[index].checked == true) {
numberDays.value = numberDays.valueAsNumber += 1
numberDaysWeekThree += 1;
} else if (weekThree[index].checked == false) {
numberDays.value = numberDays.valueAsNumber -= 1;
numberDaysWeekThree -= 1;
}
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
}
});
});
weekFour.forEach((item, index) => {
item.addEventListener(‘change’, (event) => {
if (weekFour[index].value == “Whole week”) {
if (weekFour[index].checked == true) {
numberWeeks.value = numberWeeks.valueAsNumber += 1;
weekFour.map(x => {
for (i = 1; i < weekFour.length; i++) {
weekFour[i].disabled = true;
weekFour[i].checked = true;
}
})
} else if (weekFour[index].checked == false) {
numberWeeks.value = numberWeeks.valueAsNumber -= 1;
weekFour.map(x => {
for (i = 1; i < weekFour.length; i++) {
weekFour[i].disabled = false;
weekFour[i].checked = false;
}
})
numberDaysWeekFour= 0;
}
if (numberDays.valueAsNumber - numberDaysWeekFour > 0) {
numberDays.valueAsNumber -= numberDaysWeekFour;
} else if (numberDays.valueAsNumber – numberDaysWeekFour <= 0) {
numberDays.valueAsNumber = numberDaysWeekOne + numberDaysWeekTwo + numberDaysWeekThree;
}
getPrice(weeksPrice, numberWeeks, rateWeeks);
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
} else if (weekFour[index].value != "Whole week") {
if (weekFour[index].checked == true) {
numberDays.value = numberDays.valueAsNumber += 1
numberDaysWeekFour += 1;
} else if (weekFour[index].checked == false) {
numberDays.value = numberDays.valueAsNumber -= 1;
numberDaysWeekFour -= 1;
}
getPrice(daysPrice, numberDays, rateDays);
getTotalPrice();
}
});
});