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>

1 Answer 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.