I output a bunch of input checkboxes and radio buttons in a form using php like this
if($product['type']==1)
{
$selector = "<input type='checkbox' class='product' data-price='".$product['price']."' name='prod_".$product['pid']."' id='prod_".$product['pid']."' value='".$product['pid']."'>";
}
elseif($product['type']==2)
{
$selector = "<input type='radio' required class='product' data-price='".$product['price']."' name='cat_".$product['id']."' id='cat_".$product['id']."' value='".$product['pid']."'>";
}
As you can see these input boxes hold a data-price
element and a class of product
Im then using jquery to listen for when elements with the product class change like this
$(".product").change(function(){
var product = $(this);
var price = product.data('price');
if(product.is(':checked')) {
total = total + price;
} else {
total = total - price;
}
});
My problem is that the above never reaches the else clause when the product
var is a radio button. It works without problems when the product
var is a checkbox. What can i do to solve this?