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; })​​ 

jsfiddle demo


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -