title: How to substract checkbox value when combobox change
body: <p>I have an issue with my code. How to substract checkbox value when combobox change. I hope anybody here can help me.</p>
  
  <p>Here is my js code:</p>
  
  <pre><code>//javascript for adding checkbox value and display in text.
      &lt;script&gt;
      $(document).ready(function(){
          $('input[type=checkbox]').click(function(e){
              $('#txtInput').val($(this).val())
              var total = 0;
              var text;
              $("input[type=checkbox]:checked").each(function(i,ch) {
                  total += parseFloat($(this).val());
              });
              $("#txtInput").val(total);
          }); 
      });   
  &lt;/script&gt;
  
  //javascript for substract checkbox value when combobox change
  &lt;script&gt;
  $(document).ready(function(){
      $('.xyz').change(function(){
          var tmp = $(this).closest('tr').find("input[type='checkbox']").attr('id');
       var substract = 0;
              $('#'+tmp+'').prop("checked",false)+(substract -= parseFloat($('#'+tmp+'').val())); 
          $("#txtInput").val(substract);
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>And here is my HTML code:</p>
  
  <pre><code>&lt;table&gt;
     &lt;tr&gt;
        &lt;th&gt;SELECTION&lt;/th&gt;
        &lt;th&gt;ACTION&lt;/th&gt;
        &lt;th&gt;FOOD NAME&lt;/th&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
        &lt;td&gt;&lt;select class="xyz" name="xyz1" id="xyz1"&gt;&lt;option &gt;Cancel&lt;/option&gt;
        &lt;option&gt;Take&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input type="checkbox" name="check1" id="check1" value="1" /&gt;&lt;/td&gt;
        &lt;td&gt;French Fries&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
        &lt;td&gt;&lt;select class="xyz" name="xyz2" id="xyz2"&gt;&lt;option &gt;Cancel&lt;/option&gt;
        &lt;option&gt;Take&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input type="checkbox" name="check2" id="check2" value="3" /&gt;&lt;/td&gt;
        &lt;td&gt;Pizza&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
        &lt;td&gt;&lt;select class="xyz" name="xyz3" id="xyz3"&gt;&lt;option &gt;Cancel&lt;/option&gt;
        &lt;option&gt;Take&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input type="checkbox" name="check3" id="check3" value="5" /&gt;&lt;/td&gt;
        &lt;td&gt;Beef Burger&lt;/td&gt;
     &lt;/tr&gt;
  &lt;/table&gt;
       &lt;input type="text" name="txtInput" id="txtInput" /&gt;
  </code></pre>
  
  <p>First, if I select "Take" in combobox and click checkbox the value will be shown into text.
  Second, if I do it again the checkbox will be add the value and show the result into text.
  Third, this my problem. If I change combobox into "Cancel" the checkbox only uncheck but can't decrease the value. I want if I change combobox into "Cancel" the value decrease according checkbox selection value and checkbox uncheck.
  For any help, I really appreciate it. Thanks.</p>