BeloglazowaYlya
New Member
I want to to put a condition for a jquery element in one part of the code in the function. The idea is that input.other[type="checkbox"] doesn't get the same ability to uncheck the other checkbox, but gets the ability to perform the other actions well. here is the FiddleHTML\[code\]<input type="checkbox" name="accs" icost="5000" class="arms" />Arm 1: $5000<br/><input type="checkbox" name="accs" icost="6000" class="arms" />Arm 2: $6000<br/><input type="checkbox" name="accs" icost="7000" class="neck" />Neck 1: $7000<br/><input type="checkbox" name="accs" icost="8000" class="neck" />Neck 2: $8000<br/><input type="checkbox" name="accs" icost="12000" class="other" />Other 1: $12000<br /><input type="checkbox" name="accs" icost="8000" class="other" />Other 2: $20000<br /><div id="total">$5000</div>\[/code\]The javascript code:\[code\]var items = $('input.arms[type="checkbox"], input.neck[type="checkbox"], input.other[type="checkbox"]');// get the initial total and store in a data for use later (resets as needed)var total = $('#total');total.data("currentvalue", parseFloat(total.text().replace(/[^0-9\,]+/g, "")));items.change(function () {var currenttotal = total.data("currentvalue");//exlude input.other[type="checkbox"] from herevar myClass = $(this).attr('class');var thisGroup = $('.' + myClass);var notme = $('.' + myClass + ':checked').not(this);var notmeCost = (notme.length ? notme.attr('icost') : ($(this).is(':checked') ? 0 : $(this).attr('icost')));notme.prop('checked', false);//ends here//include input.other[type="checkbox"] from herecurrenttotal = currenttotal - notmeCost;total.fadeOut(300);thisGroup.filter(':checked').each(function (i) { var cost = $(this).attr('icost'); currenttotal = currenttotal + parseFloat(cost);});total.data("currentvalue", currenttotal);total.text("$" + currenttotal.formatMoney(0, ',', '.')); // fix your format here as neededtotal.fadeIn(300);});\[/code\]