javascript - jquery calculate multiple box keyup function -
here html code:
<tbody> <?php $x = 1; while($x < 26){ ?> <tr> <td><?php echo $x; ?></td> <td> <?php $sql_produk = mysql_query("select stok.id id, jenis_barang.nama, stok.stok stok left join jenis_barang on jenis_barang.id = stok.jenisbarang_id toko = '$administrator_id' group stok.jenisbarang_id")or die(mysql_error()); ?> <select class="form-control select2me" name="produk_<?php echo $x; ?>"> <option value="0">select...</option> <?php while($row_produk = mysql_fetch_array($sql_produk)) { ?> <option value="<?php echo $row_produk['id'] ?>"> <?php echo $row_produk['nama'] ?> (stok tersedia: <?php echo $row_produk['stok'] ?>) </option> <?php } ?> </select> </td> <td><input class="form-control" type="text" name="produk_custom_<?php echo $x; ?>" /></td> <td><input class="form-control" type="text" name="qty_<?php echo $x; ?>" id="id_qty_<?php echo $x; ?>" /></td> <td><input class="form-control" type="text" name="harga_<?php echo $x; ?>" id="id_harga_<?php echo $x; ?>" /></td> <td><input class="form-control" type="text" name="harga_markup_<?php echo $x; ?>" id="id_harga_markup_<?php echo $x; ?>" value="0" /></td> <td><input class="form-control" type="text" id="id_total_<?php echo $x; ?>" disabled /><input type="text" class="classtotal" value="0" name="total_<?php echo $x; ?>" id="ids_total_<?php echo $x; ?>"></td> <td><input class="form-control" type="text" id="id_total_markup_<?php echo $x; ?>" disabled /><input type="hidden" class="form-control" value="0" name="total_markup<?php echo $x; ?>" id="ids_total_markup_<?php echo $x; ?>" ></td> </tr> <?php $x++; } ?> </tbody> <tr> <td width="5%"> </td> <td width="20%"> </td> <td width="20%"> </td> <td width="5%"> </td> <td width="12.5%"> </td> <td width="12.5%" style="text-align:right"><h4 style="font-weight:bold">total</h4></td> <td width="12.5%"><input class="form-control" type="text" name="total_all" id="id_total_all" disabled /></td> <td width="12.5%"><input class="form-control" type="text" name="total_markup_all" id="id_total_markup_all" disabled /></td>
and javascript code
<script type="text/javascript"> $('.totalamountcb').change(function () { calculateinvoicetotals(); }).change(); function format1(n, currency) { return currency + " " + n.tofixed(0).replace(/./g, function(c, i, a) { return > 0 && c !== "," && (a.length - i) % 3 === 0 ? "." + c : c; }); } $(document).ready(function(){ $('#id_harga_1, #id_qty_1').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_1').val()); qty =parseint($('#id_qty_1').val()); total =qty * harga; $('#ids_total_1').val(total); $('#id_total_1').val(format1(total, "rp.")); }); $('#id_harga_2, #id_qty_2').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_2').val()); qty =parseint($('#id_qty_2').val()); total =qty * harga; $('#ids_total_2').val(total); $('#id_total_2').val(format1(total, "rp.")); }); $('#id_harga_3, #id_qty_3').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_3').val()); qty =parseint($('#id_qty_3').val()); total =qty * harga; $('#ids_total_3').val(total); $('#id_total_3').val(format1(total, "rp.")); }); $('#id_harga_4, #id_qty_4').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_4').val()); qty =parseint($('#id_qty_4').val()); total =qty * harga; $('#ids_total_4').val(total); $('#id_total_4').val(format1(total, "rp.")); }); $('#id_harga_5, #id_qty_5').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_5').val()); qty =parseint($('#id_qty_5').val()); total =qty * harga; $('#ids_total_5').val(total); $('#id_total_5').val(format1(total, "rp.")); }); $('#id_harga_6, #id_qty_6').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_6').val()); qty =parseint($('#id_qty_6').val()); total =qty * harga; $('#ids_total_6').val(total); $('#id_total_6').val(format1(total, "rp.")); }); $('#id_harga_7, #id_qty_7').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_7').val()); qty =parseint($('#id_qty_7').val()); total =qty * harga; $('#ids_total_7').val(total); $('#id_total_7').val(format1(total, "rp.")); }); $('#id_harga_8, #id_qty_8').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_8').val()); qty =parseint($('#id_qty_8').val()); total =qty * harga; $('#ids_total_8').val(total); $('#id_total_8').val(format1(total, "rp.")); }); $('#id_harga_9, #id_qty_9').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_9').val()); qty =parseint($('#id_qty_9').val()); total =qty * harga; $('#ids_total_9').val(total); $('#id_total_9').val(format1(total, "rp.")); }); $('#id_harga_10, #id_qty_10').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_10').val()); qty =parseint($('#id_qty_10').val()); total =qty * harga; $('#ids_total_10').val(total); $('#id_total_10').val(format1(total, "rp.")); }); $('#id_harga_11, #id_qty_11').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_11').val()); qty =parseint($('#id_qty_11').val()); total =qty * harga; $('#ids_total_11').val(total); $('#id_total_11').val(format1(total, "rp.")); }); $('#id_harga_12, #id_qty_12').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_12').val()); qty =parseint($('#id_qty_12').val()); total =qty * harga; $('#ids_total_12').val(total); $('#id_total_12').val(format1(total, "rp.")); }); $('#id_harga_13, #id_qty_13').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_13').val()); qty =parseint($('#id_qty_13').val()); total =qty * harga; $('#ids_total_13').val(total); $('#id_total_13').val(format1(total, "rp.")); }); $('#id_harga_14, #id_qty_14').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_14').val()); qty =parseint($('#id_qty_14').val()); total =qty * harga; $('#ids_total_14').val(total); $('#id_total_14').val(format1(total, "rp.")); }); $('#id_harga_15, #id_qty_15').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_15').val()); qty =parseint($('#id_qty_15').val()); total =qty * harga; $('#ids_total_15').val(total); $('#id_total_15').val(format1(total, "rp.")); }); $('#id_harga_16, #id_qty_16').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_16').val()); qty =parseint($('#id_qty_16').val()); total =qty * harga; $('#ids_total_16').val(total); $('#id_total_16').val(format1(total, "rp.")); }); $('#id_harga_17, #id_qty_17').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_17').val()); qty =parseint($('#id_qty_17').val()); total =qty * harga; $('#ids_total_17').val(total); $('#id_total_17').val(format1(total, "rp.")); }); $('#id_harga_18, #id_qty_18').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_18').val()); qty =parseint($('#id_qty_18').val()); total =qty * harga; $('#ids_total_18').val(total); $('#id_total_18').val(format1(total, "rp.")); }); $('#id_harga_19, #id_qty_19').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_19').val()); qty =parseint($('#id_qty_19').val()); total =qty * harga; $('#ids_total_19').val(total); $('#id_total_19').val(format1(total, "rp.")); }); $('#id_harga_20, #id_qty_20').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_20').val()); qty =parseint($('#id_qty_20').val()); total =qty * harga; $('#ids_total_20').val(total); $('#id_total_20').val(format1(total, "rp.")); }); $('#id_harga_21, #id_qty_21').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_21').val()); qty =parseint($('#id_qty_21').val()); total =qty * harga; $('#ids_total_21').val(total); $('#id_total_21').val(format1(total, "rp.")); }); $('#id_harga_22, #id_qty_22').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_22').val()); qty =parseint($('#id_qty_22').val()); total =qty * harga; $('#ids_total_22').val(total); $('#id_total_22').val(format1(total, "rp.")); }); $('#id_harga_23, #id_qty_23').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_23').val()); qty =parseint($('#id_qty_23').val()); total =qty * harga; $('#ids_total_23').val(total); $('#id_total_23').val(format1(total, "rp.")); }); $('#id_harga_24, #id_qty_24').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_24').val()); qty =parseint($('#id_qty_24').val()); total =qty * harga; $('#ids_total_24').val(total); $('#id_total_24').val(format1(total, "rp.")); }); $('#id_harga_25, #id_qty_25').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_25').val()); qty =parseint($('#id_qty_25').val()); total =qty * harga; $('#ids_total_25').val(total); $('#id_total_25').val(format1(total, "rp.")); }); $('#id_harga_markup_1, #id_qty_1').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_1').val()); qty =parseint($('#id_qty_1').val()); total =qty * harga; $('#ids_total_markup_1').val(total); $('#id_total_markup_1').val(format1(total, "rp.")); }); $('#id_harga_markup_2, #id_qty_2').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_2').val()); qty =parseint($('#id_qty_2').val()); total =qty * harga; $('#ids_total_markup_2').val(total); $('#id_total_markup_2').val(format1(total, "rp.")); }); $('#id_harga_markup_3, #id_qty_3').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_3').val()); qty =parseint($('#id_qty_3').val()); total =qty * harga; $('#ids_total_markup_3').val(total); $('#id_total_markup_3').val(format1(total, "rp.")); }); $('#id_harga_markup_4, #id_qty_4').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_4').val()); qty =parseint($('#id_qty_4').val()); total =qty * harga; $('#ids_total_markup_4').val(total); $('#id_total_markup_4').val(format1(total, "rp.")); }); $('#id_harga_markup_5, #id_qty_5').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_5').val()); qty =parseint($('#id_qty_5').val()); total =qty * harga; $('#ids_total_markup_5').val(total); $('#id_total_markup_5').val(format1(total, "rp.")); }); $('#id_harga_markup_6, #id_qty_6').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_6').val()); qty =parseint($('#id_qty_6').val()); total =qty * harga; $('#ids_total_markup_6').val(total); $('#id_total_markup_6').val(format1(total, "rp.")); }); $('#id_harga_markup_7, #id_qty_7').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_7').val()); qty =parseint($('#id_qty_7').val()); total =qty * harga; $('#ids_total_markup_7').val(total); $('#id_total_markup_7').val(format1(total, "rp.")); }); $('#id_harga_markup_8, #id_qty_8').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_8').val()); qty =parseint($('#id_qty_8').val()); total =qty * harga; $('#ids_total_markup_8').val(total); $('#id_total_markup_8').val(format1(total, "rp.")); }); $('#id_harga_markup_9, #id_qty_9').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_9').val()); qty =parseint($('#id_qty_9').val()); total =qty * harga; $('#ids_total_markup_9').val(total); $('#id_total_markup_9').val(format1(total, "rp.")); }); $('#id_harga_markup_10, #id_qty_10').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_10').val()); qty =parseint($('#id_qty_10').val()); total =qty * harga; $('#ids_total_markup_10').val(total); $('#id_total_markup_10').val(format1(total, "rp.")); }); $('#id_harga_markup_11, #id_qty_11').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_11').val()); qty =parseint($('#id_qty_11').val()); total =qty * harga; $('#ids_total_markup_11').val(total); $('#id_total_markup_11').val(format1(total, "rp.")); }); $('#id_harga_markup_12, #id_qty_12').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_12').val()); qty =parseint($('#id_qty_12').val()); total =qty * harga; $('#ids_total_markup_12').val(total); $('#id_total_markup_12').val(format1(total, "rp.")); }); $('#id_harga_markup_13, #id_qty_13').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_13').val()); qty =parseint($('#id_qty_13').val()); total =qty * harga; $('#ids_total_markup_13').val(total); $('#id_total_markup_13').val(format1(total, "rp.")); }); $('#id_harga_markup_14, #id_qty_14').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_14').val()); qty =parseint($('#id_qty_14').val()); total =qty * harga; $('#ids_total_markup_14').val(total); $('#id_total_markup_14').val(format1(total, "rp.")); }); $('#id_harga_markup_15, #id_qty_15').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_15').val()); qty =parseint($('#id_qty_15').val()); total =qty * harga; $('#ids_total_markup_15').val(total); $('#id_total_markup_15').val(format1(total, "rp.")); }); $('#id_harga_markup_16, #id_qty_16').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_16').val()); qty =parseint($('#id_qty_16').val()); total =qty * harga; $('#ids_total_markup_16').val(total); $('#id_total_markup_16').val(format1(total, "rp.")); }); $('#id_harga_markup_17, #id_qty_17').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_17').val()); qty =parseint($('#id_qty_17').val()); total =qty * harga; $('#ids_total_markup_17').val(total); $('#id_total_markup_17').val(format1(total, "rp.")); }); $('#id_harga_markup_18, #id_qty_18').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_18').val()); qty =parseint($('#id_qty_18').val()); total =qty * harga; $('#ids_total_markup_18').val(total); $('#id_total_markup_18').val(format1(total, "rp.")); }); $('#id_harga_markup_19, #id_qty_19').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_19').val()); qty =parseint($('#id_qty_19').val()); total =qty * harga; $('#ids_total_markup_19').val(total); $('#id_total_markup_19').val(format1(total, "rp.")); }); $('#id_harga_markup_20, #id_qty_20').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_20').val()); qty =parseint($('#id_qty_20').val()); total =qty * harga; $('#ids_total_markup_20').val(total); $('#id_total_markup_20').val(format1(total, "rp.")); }); $('#id_harga_markup_21, #id_qty_21').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_21').val()); qty =parseint($('#id_qty_21').val()); total =qty * harga; $('#ids_total_markup_21').val(total); $('#id_total_markup_21').val(format1(total, "rp.")); }); $('#id_harga_markup_22, #id_qty_22').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_22').val()); qty =parseint($('#id_qty_22').val()); total =qty * harga; $('#ids_total_markup_22').val(total); $('#id_total_markup_22').val(format1(total, "rp.")); }); $('#id_harga_markup_23, #id_qty_23').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_23').val()); qty =parseint($('#id_qty_23').val()); total =qty * harga; $('#ids_total_markup_23').val(total); $('#id_total_markup_23').val(format1(total, "rp.")); }); $('#id_harga_markup_24, #id_qty_24').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_24').val()); qty =parseint($('#id_qty_24').val()); total =qty * harga; $('#ids_total_markup_24').val(total); $('#id_total_markup_24').val(format1(total, "rp.")); }); $('#id_harga_markup_25, #id_qty_25').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_markup_25').val()); qty =parseint($('#id_qty_25').val()); total =qty * harga; $('#ids_total_markup_25').val(total); $('#id_total_markup_25').val(format1(total, "rp.")); }); }); </script>
so have 25 row of product input box (for invoice) 1 row total price of inquiry
so have make multiply code qty * harga (harga = price), @ bottom of table have total input box disabled, want when input qty / harga, want total automatically sum 25 row of total price.. how can that? i've searched , tried suggestion here doesnt work, way there way can loop javascript code 25 box? ive tried didnt work well
thanks help
you need use running total.
put under var runningtotal = 0
under $('document').ready()
then each time work out total of row. runningtotal += total
.
at end runningtotal
contain sum of rows.
$(document).ready(function(){ var runningtotal = 0; $('#id_harga_1, #id_qty_1').keyup(function(){ <!-- ambil nilai !--> harga =parseint($('#id_harga_1').val()); qty =parseint($('#id_qty_1').val()); total =qty * harga; runningtotal += total; // adds running total variable }); $('#ids_total_markup_25').val(total); $('#id_total_markup_25').val(format1(runningtotal, "rp.")); }); });
this add running total after each keyup event. might want consider using different event onblur
trigger adding event. or adding button add total.
Comments
Post a Comment