Is this jQuery, or JavaScript? My assignment disallows the use of jQuery.
function calculateTotal() {
var collection = document.getElementsByName('deliveryType'),
cds = document.getElementsByName('cd[]'),
cdTotal = 0,
L = collection.length;
while(L--) {
if(collection[L].checked) { // get shipping costs
collection = Number(collection[L].getAttribute('title'));
break;
}
}
L = cds.length;
while(L--) {
if(cds[L].checked) { //add total prices
cdTotal += Number(cds[L].getAttribute('title'));
}
}
// output total
document.getElementById('total').value = collection + cdTotal;
}