javascript - Totalling checked checkboxes amidst changes -
i have page many checkboxes, each of tied product price. i'm trying use jquery give real-time readout of 1) number of products, , 2) total price of user's selections.
this should easy: have done like:
$(input).change( function(){ var sum = $(input:checked).length var price_total = $(input:checked).length * 1.99 })
the complication
the element or elements being changed not counted in above code. seems when clicking blank checkbox check it, jquery consider current element 'not checked' rather 'checked', i.e. reflects checkbox before change. result, code gets more complicated accept changed items.
is there elegant , simple way around this?
not sure if code posted you're running, among other things, code missing quotes in $
selectors. however, working me:
$(':checkbox').change( function(){ var sum = $(':checked').length; var price_total = sum*1.99; })
Comments
Post a Comment