hi everyone,
I'm try to count the number of checked checkboxes, if two are checked the price of the item in the hidden field is £3.00 and for any additional check boxes the price should be added by 1,
I don't seem to find a solution, any help would be appriciated. all the checkboxes have the Id="veg"; and hidden field has Id="my_item-price"
function SetHiddenFieldValue()
{
var itemPrice = 3;
var totalChecked = 0;
var veg = document.getElementsById("veg");
for(j=0; j < veg.length;j ++)
{
if(veg[j].checked)
{
totalChecked += 1;
}
}
return totalChecked
if (totalChecked > 2) {
totalChecked = totalChecked -2;
totalChecked = totalChecked * 1;
itemPrice = itemPrice + totalChecked;
}
document.getElementById('my-item-price').value = itemPrice;
}