How to count the number of checkboxes and add to the price
<p>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,</p>

<p>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"</p>

<pre><code>        function SetHiddenFieldValue()
        {
            var itemPrice = 3;
         var totalChecked = 0;
         var veg = document.getElementsById("veg");
         for(j=0; j &lt; veg.length;j ++)
         {
        if(veg[j].checked)
        {
       totalChecked += 1;
         }
         }
  return totalChecked

    if (totalChecked &gt; 2) {
  totalChecked = totalChecked -2;
  totalChecked = totalChecked * 1;
  itemPrice = itemPrice + totalChecked;

 }

         document.getElementById('my-item-price').value = itemPrice;
}
</code></pre>
