title: How to perform a computation using trigger event?
body: <p>I created a form list update. And every row has a sets of textbox.
  Each textbox has its own value based on my query result. And at the end of every column there is a selection box. And you can choose VALID or INVALID. My goal is simple, if the user select an INVALID status for each row. The value of the quantity and price and total will be set to 0 and the computation below will be decreased based on the the item/row that has been set to the selection. If INVALID, the selected row will be deducted to the subtotal amount. </p>
  
  <p><strong>Problems:</strong> </p>
  
  <ol>
  <li>In triggering if the user set the status to INVALID I have no
  problem but if the user trigger the selection back to VALID. I can't
  get back again my value.</li>
  <li>If the user set the to INVALID, there is no deduction of total in the subtotal. Becuase I don't know how to do that.</li>
  </ol>
  
  <p>Here's a bit of my code below:</p>
  
  <pre><code>Here is my jquery section:
  
  $('[id^=qty],[id^=price]').on('change',function() {
  
          var index = this.id.match(/\d+/)[0];
          var qty = parseInt($('#qty'+index).val());
          var price = parseFloat($('#price'+index).val());
          var total = 0;
  
          $('#total'+index).val((qty * price ? qty * price : 0).toFixed(2));
  
          var total = 0;
          $('[id^=total]').each(function(index){
              total+=parseFloat($(this).val()?$(this).val():0);
          });
          $('#sum_of_total').val(total.toFixed(2));
  
          var vatable = total / 1.12;
          var vatable_amt = vatable * 0.12;
          var totalVat = vatable + vatable_amt;
  
          $('#vatable').val(vatable.toFixed(2)); 
          $("#vatable_amount").val(vatable_amt.toFixed(2));
          $("#gtotal").val(totalVat.toFixed(2));
  
      });
  
      $('[id^=status_validate]').on('change',function(){
  
         var index = this.id.match(/\d+/)[0];
  
         var status_set = $("#status_validate"+index).val();
         var price_set = $("#price"+index).val();
         var qty_set = $("#qty"+index).val();
         var total_set = $("#total"+index).val();
  
         var temp_price = price_set;
         var temp_qty = qty_Set;
         var temp_total = tota_set;
  
         console.log(status_set);
  
         if(status_set == 'VALID'){
  
              $("#price"+index).val(price_set);
              $("#qty"+index).val(price_set);
              $("#total"+index).val(price_set);
  
         }else{
  
              price_set = 0.00;
              qty_set = 0.00;
              total_set = 0.00;
  
              $("#price"+index).val(price_set);
              $("#qty"+index).val(price_set);
              $("#total"+index).val(price_set);
  
         }
  
      });
  </code></pre>
  
  <p>And here is the loop part</p>
  
  <pre><code>$val = 0;
  
  foreach($order_info_list-&gt;result_array() as $details){
  
      $val++;
  
      $vatable_input = $details['vatable_input'];
      $vatable_amount = $details['vatable_amount'];
      $total_amount_due = $details['total_amount_due'];
  
      echo "&lt;tr&gt;";
          echo "&lt;td&gt;&lt;input type='text' name='itemdesc[]' value = ".$details['item_desc']." /&gt;&lt;/td&gt;";
          echo "&lt;td&gt;&lt;input type='text' name='qty[]' value=".$details['item_qty']." id='qty{$val}' /&gt;&lt;/td&gt;";
          echo "&lt;td&gt;&lt;input type='text' name='price[]' value=".number_format($details['item_price'],2)." id='price$val' /&gt;&lt;/td&gt;";
          echo "&lt;td&gt;&lt;input type='text' name='total[]' class='k-textbox' id='total{$val}' style='font-family: courier; text-align: right; background-color: lightgray; color: red' readonly='readonly' value='".$details['total']."' /&gt;&lt;/td&gt;";
          echo "&lt;td width='30%'&gt;";
  
           $stat = $details['status'];
  
           echo "&lt;select name='status[]' id='status_validate[$val]'&gt;";    
               if($stat == 'VALID'){
                  echo "&lt;option value='VALID' selected='selected'&gt;VALID&lt;/option&gt;";
                  echo "&lt;option value='INVALID'&gt;INVALID&lt;/option&gt;";
               }else{
                  echo "&lt;option value='VALID'&gt;VALID&lt;/option&gt;";
                  echo "&lt;option value='INVALID' selected='selected'&gt;INVALID&lt;/option&gt;";
               }
            echo "&lt;/select&gt;";
          echo "&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  
      $idx = $details['poid'];
  
      echo "&lt;input type='hidden' name='idx[]' value='{$idx}' /&gt;";
  
      $code_x = $details['order_code'];
  
  
  
  }
  </code></pre>
  
  <p>Below is the displaying of total computaion</p>
  
  <pre><code> &lt;tr&gt;
     &lt;td&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;
     &lt;td&gt;VATable Amount:&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" class="k-textbox" value="0.00" readonly="readonly" style="color: red; text-align: right; font-family: courier" name="vatable" id="vatable" /&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
     &lt;td&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;
     &lt;td&gt;VAT Input:&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" class="k-textbox" value="0.00" readonly="readonly" style="color: red; text-align: right; font-family: courier" name="vatable_amount" id="vatable_amount" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;TOTAL AMOUNT DUE:&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" class="k-textbox" value="0.00" readonly="readonly" style="color: red; text-align: right; font-family: courier" name="subtotal" id="gtotal" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  </code></pre>
  
  <p>Here's the fiddle <a href="http://jsfiddle.net/y6d8m/4" rel="nofollow">http://jsfiddle.net/y6d8m/4</a></p>