Show and reset select with checkbox in jquery

2

In the sample code attached, item value is multiplied by the value of the respective select and displays the subtotal and total.

My question (beginner) is how to hide and remove the selectlist when the checkbox is unchecked, that is, when the checkbox is checked, the respective listlist appears always starting with the first item in the list (1 unit).

I even managed to make it work without Jquery but it was just like a "frankenstein" Thanks in advance, to all who can help.

The following is an incomplete example with jquery: link

    
asked by anonymous 21.03.2016 / 14:42

1 answer

1

What you need is to find a logic to know which input and select work together. In this case it seems to me that the common element is tr , or both share the same line.

You can do this:

$('table input:checked').each(function() {
    var tr = $(this).closest('tr');
    var qty = tr.find('.qty').val();
    var price = $(this).val();
    var amount = (qty * price) || 0;
    sum += amount;
    tr.find('.amount').text(amount);
});

jsFiddle: link

Notice that I use only inputs selected with $('table input:checked') as a starting point. So the% w_ of% within the function will be the input.

    
21.03.2016 / 16:24