Jquery store string and put it out elsewhere when checkbox is checked -
looking here. have create price check calculator. 2 things need done:
- if checkboxes different values checked overallprice has shown somewhere.
- i need summary of selected items. need put selected items beneath overallprice.
i managed point 1 work. im struggling point 2. have no clue how put checked items elsewhere.
heres how far ive got:
$(document).ready(function() { $('input[type="checkbox"]').click(function() { var total = 0; //var item = []; var $parent = $(this).closest('ul'); $parent.find('input:checked').each(function() { total += parseint($(this).val()); //item.text(); }); $parent.find('span[class^=total]').html(total + ' €'); var overallprice = 0; $('span[class^=total]').each(function() { overallprice += parseint($(this).html().replace(' €','')); }); $('.overallprice').html(overallprice) //$('.overallprice').append(item); }); });
and better understanding jsfiddle
i'd grateful help. alot!
you need loop through checked boxes , label values:
- get checked check boxes , loop through them.
- for each one, label's text content that's next , append it.
code
// checked check boxes $("input:checked").each(function () { // each one, label's text content that's next , append it. $('.overallprice').append("<br>" + $(this).next("label").text()); });
fiddle: https://jsfiddle.net/truvrurc/
Comments
Post a Comment