0

I'm developing a inventory management app using codeigniter and i want generate total price when a user entering quantity and unit price ... I have used below way to doing it but the values are not saving to database , please advice

1> this is my View

purchase_quantity purchase_unit_price purchase_total are database values

    <script>

     $(document).ready(function () {
       $(".txtMult input").keyup(multInputs);

       function multInputs() {
           var mult = 0;
           // for each row:
           $("tr.txtMult").each(function () {
               // get the values from this row:
               var $val1 = $('.val1', this).val();
               var $val2 = $('.val2', this).val();
               var $total = ($val1 * 1) * ($val2 * 1)
               $('.multTotal',this).text($total);
               mult += $total;
           });
           $("#grandTotal").text(mult);
       }
  });

</script>



      <tr class="txtMult">
                <td>
                <input  class="val1" type="text" name="purchase_unit_price" value="<?php echo set_value('val1', $this -> form_data -> purchase_unit_price); ?>"/>
    <?php echo form_error('purchase_unit_price'); ?>
                <td>
                   <input  class="val2"type="text" name="purchase_quantity"  value="<?php echo set_value('val2', $this -> form_data -> purchase_quantity); ?>"/>
    <?php echo form_error('purchase_quantity'); ?>
                </td>
            <td>
                <input  class="multTotal"type="text" name="purchase_total"  value="<?php echo set_value('multTotal', $this -> form_data -> purchase_total); ?>"/> 
<?php echo form_error('purchase_total'); ?> 

            </td>
        </tr>
4

1 回答 1

1

use this

script :

      $('.txtMult').each(function(i){
       val1 = $('.val1').val();
         val2 = $('.val2').val();
        total = parseInt(val1)+parseInt(val2);

         $('.multTotal').val(total);
    });

I think it will help

于 2013-07-30T05:03:18.560 回答