vendredi 10 juin 2016

Calculate value for each rows from two field on dynamical form


I have problem to calculate total in dynamical form, my form like this enter image description here

How I can get total in Field Total from calculating Harga Satuan and Jumlah for each rows?

This is my code to generate new rows :

jQuery(function(){
    var counter = 0;
    jQuery('button.tambah').click(function(event){
        event.preventDefault();
        counter++;
        var newRow = jQuery('<tr><td align="left"><select name="namaBahan'+counter+'" id="namaBahan'+counter+'"><?php $sql = pg_query("SELECT DISTINCT bahan_baku_menu.namabahanbaku FROM foodie.bahan_baku_menu ORDER BY namabahanbaku ASC;"); while ($row = pg_fetch_assoc($sql)) { ?> <option value="<?php echo $row['namabahanbaku']; ?>"><?php echo $row['namabahanbaku']; ?></option><?php } ?></select></td><td align="left"><input id="harga_satuan'+counter+'" name="harga_satuan'+counter+'" style="width: 150px" type="text"></td><td align="left"><select name="satuan'+counter+'" id="satuan'+counter+'"><?php $sqls = pg_query("SELECT DISTINCT konversi.satuanawal FROM foodie.konversi ORDER BY satuanawal ASC;"); while ($rows = pg_fetch_assoc($sqls)) { ?><option value="<?php echo $rows['satuanawal']; ?>"><?php echo $rows['satuanawal']; ?></option><?php }pg_close($db); ?></select></td><td align="left"><input id="jumlah'+counter+'" name="jumlah'+counter+'" style="width: 50px" type="text"></td><td align="left"><input id="total'+counter+'" name="total'+counter+'" style="width: 150px" readonly="readonly" type="text"></td></tr>');
        jQuery('tbody.newTable').append(newRow);
    });
});

Aucun commentaire:

Enregistrer un commentaire