This is more of a problem with JavaScript than PHP, but I'm hoping someone here knows how to solve this particular puzzle 🙂
I've got a form with six rows (this isn't fixed though) of three radio buttons on it.
The three radio buttons on each row are named as "meal[x]" in the HTML, where x is a number from 1 to 6 (or however many rows there are)
Each radio button on the row has a different value associated with it in the HTML - B, L, and BL.
Whenever one of these radio buttons is checked, I need to be able to scan through ALL of the radio buttons on the page and calculate the sub-total for the order based on the radio buttons.
However, because I'm using "meal[x]" as the name, JavaScript doesn't seem to want to go through them all. Here's the code:
function calculateTotals() {
subtotal=0;
for(i=1; i<=<?=$num_delegates?>; i++){
switch (document.elements['meal['+eval(i)+']'].value){
case "B":
subtotal = subtotal + <?=MEAL_BREAKFAST?>;
break;
case "L":
subtotal = subtotal + <?=MEAL_LUNCH?>;
break;
case "BL":
subtotal = subtotal + <?=MEAL_BOTH?>;
break;
}
document.elements['sub_total_td'].innerHTML = "£ "+subtotal;
}
}
Any help at all is greatly appreciated, guys 🙂