cosmin1987 Posted May 20, 2017 Report Posted May 20, 2017 (edited) Salutare, am o mica problema, care este destul de simpla. Am urmatoarele checkbox-uri <input type="checkbox" class="add" data-amount="30" id="extra_units_3" value="1" /> <input type="checkbox" class="add" data-amount="40" id="extra_units_4" value="1" /> <input type="checkbox" class="add" data-amount="50" id="extra_units_5" value="1" /> <input type="checkbox" class="add" data-amount="60" id="extra_units_6" value="1" /> si imi calculeaza foarte simplu cu jquery : $('.add').click(function() { if($(this).is(':checked')) { $('#total').text(parseInt($('#total').text()) + parseInt($(this).data('amount'))); } else { $('#total').text(parseInt($('#total').text()) - parseInt($(this).data('amount'))); } }); As vrea sa mai adaug un checkbox selected care sa nu poata fi modificat, care sa aibe data-amount="" stabilit de mine si apoi fiecare checkbox sa adauge valoarea (data-amount) peste valoarea checkbox-ului adaugat de mine. Multumesc anticipat Edited May 20, 2017 by cosmin1987 Quote
u0m3 Posted May 20, 2017 Report Posted May 20, 2017 Imi este neclara formularea 51 minutes ago, cosmin1987 said: [...] adaug un checkbox selected care sa nu poata fi modificat [...] Te referi sa fie checked si disabled? Adica asa? <input type="checkbox" class="add" data-amount="1337" disabled="disabled" checked="checked"> 1 Quote
UnixDevel Posted May 20, 2017 Report Posted May 20, 2017 o alta solutie ar fi sa il ai hidden , ? Quote
cosmin1987 Posted May 20, 2017 Author Report Posted May 20, 2017 Da corect hidden vreau sa il fac, dar din pacate am o problema, cand checkbox-ul se selecteaza incepe sa adune valorile de la data-amount, si as dorii sa pluseze suma checkbox-ului hidden <input type="checkbox" class="add" data-amount="1337" disabled="disabled" checked="checked"> adica sa imi adauge la 1337 valorile checkbox-urilor selectate. Quote
Pintilei Posted May 20, 2017 Report Posted May 20, 2017 (edited) Sper ca am inteles exact ce ai nevoie: https://jsfiddle.net/csstmuzd/3/ PS: Atentie la parseInt, poate o sa ai nevoie si de float, deci foloseste Number() Edited May 20, 2017 by Pintilei 2 Quote
cosmin1987 Posted May 20, 2017 Author Report Posted May 20, 2017 Da ai inteles perfect. Multumesc frumos Quote