You forgot to put ()
at: onchange="calculateTotal()"
, so the function is never called. With that change, the total is shown when the user modify the "leeftijd" select box.
To compute total:
function getLunchPrice() {
var lunchPrice=0;
var theForm = document.forms["totaalBerekening"];
var selectedLeeftijd = theForm.elements;
for (var i=0; i < selectedLeeftijd.length; i++) {
var field = selectedLeeftijd[i];
if (field.name == "leeftijd[]") lunchPrice += leeftijdPrijs[field.value];
}
return lunchPrice;
}
Then add two calls to calculateTotal()
: one in the addRow()
function, another when the page is loaded, eventually nicer identifiers for the fields ;-)