function hitung() {
var n = [0];
var price = document.getElementsByName("price[]")[n].value;
var qty = document.getElementsByName("qty[]")[n].value;
var total = parseInt(price) * parseInt(qty);
document.getElementsByName("total[]")[n].value = total;
}
</script>
<tr>
<td><input type="text" name="price" value="<?php echo $r['price']; ?>" onKeyUp='hitung()' class="fixed" /></td>
<td><input type="text" name="qty" value="0" onKeyUp='hitung()' class="fixed"/></td>
<td align="right"><input type="text" name="total" value="0" class="fixed" readonly="total" /></td>
</tr>
<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
<colgroup>
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
</colgroup>
<thead>
<tr>
<th class="head0">PO #</th>
<th class="head1">Product Name</th>
<th class="head0">Product #</th>
<th class="head1">Design Name</th>
<th class="head0">Description</th>
<th class="head1">Price</th>
<th class="head0">x</th>
<th class="head0">Qty</th>
<th class="head1">Total</th>
<th class="head0">Act</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="7" class="head0">GRAND TOTAL</th>
<th class="head0"><input type="text" name="total_qty" value="0" class="total" readonly="" /></th>
<th class="head1"><input type="text" name="total_qty" value="0" class="total" readonly="" /></th>
<th class="head0"></th>
</tr>
</tfoot>
<?php
$sql="select * from cart_po";
$query=mysql_query($sql);
while ($r=mysql_fetch_array($query)){
?>
<tbody>
<tr>
<td><?php echo $r['id_detail']; ?></td>
<td><?php echo $r['product_name']; ?></td>
<td><?php echo $r['product_code']; ?></td>
<td><?php echo $r['design']; ?></td>
<td><?php echo $r['description']; ?></td>
<td><input type="text" name="price[]" value='<?php echo $r['price']; ?>' class="price" /></td>
<td style="text-align: center;">x</td>
<td><input type="text" name="qty[]" value='0' class="qty"/></td>
<td align="right"><input type="text" name="total[]" value="0" class="total" readonly="total[]" /></td>
<td><a href="home.php?source=delete-cart-po&code=<?php echo $r['product_code'];?>" onclick='return confirm("Are you sure to delete this data?");'><img src="images/icons/default/trash.png" title="Delete Data" /></a></td>
</tr>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".price").keyup(function(){
var total = $(this).parent().next().next().next().find('.total');
var qty = $(this).parent().next().next().find('.qty');
$(total).val($(this).val() * $(qty).val());
});
$(".qty").keyup(function(){
var total = $(this).parent().next().find('.total');
var price = $(this).parent().prev().prev().find('.price');
$(total).val($(this).val() * $(price).val());
});
</script>
<?php }?>
</tbody>
</table>
<tfoot>
<tr>
<th colspan="7" class="head0">GRAND TOTAL</th>
<th class="head0"><input type="text" name="total_qty" value="0" readonly="" /></th>
<th class="head1"><input type="text" name="total_price" value="0" readonly="" /></th>
<th class="head0"></th>
</tr>
</tfoot>
<?php
$sql="select * from cart_po";
$query=mysql_query($sql);
while ($r=mysql_fetch_array($query)){
?>
<tbody>
<tr>
<td><?php echo $r['id_detail']; ?></td>
<td><?php echo $r['product_name']; ?></td>
<td><?php echo $r['product_code']; ?></td>
<td><?php echo $r['design']; ?></td>
<td><?php echo $r['description']; ?></td>
<td><input type="text" name="price[]" value='<?php echo $r['price']; ?>' class="price" /></td>
<td style="text-align: center;">x</td>
<td><input type="text" name="qty[]" value='0' class="qty"/></td>
<td align="right"><input type="text" name="total[]" value="0" class="total" readonly="total[]" /></td>
<td><a href="home.php?source=delete-cart-po&code=<?php echo $r['product_code'];?>" onclick='return confirm("Are you sure to delete this data?");'><img src="images/icons/default/trash.png" title="Delete Data" /></a></td>
</tr>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".price").keyup(function(){
var total = $(this).parent().next().next().next().find('.total');
var qty = $(this).parent().next().next().find('.qty');
$(total).val($(this).val() * $(qty).val());
});
$(".qty").keyup(function(){
var total = $(this).parent().next().find('.total');
var price = $(this).parent().prev().prev().find('.price');
$(total).val($(this).val() * $(price).val());
});
function grandTotal(){
var total = 0;
var qty = 0;
$('.total').each(function(){
total += parseFloat($(this).val());
});
$('.qty.').each(function(){
qty += parseFloat($(this).val());
});
$('input[name="total_price"]').val(total);
$('input[name="total_qty"]').val(qty);
}
</script>
<?php }?>
</tbody>
</table>
<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
<colgroup>
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
</colgroup>
<thead>
<tr>
<th class="head0">PO #</th>
<th class="head1">Product Name</th>
<th class="head0">Product #</th>
<th class="head1">Design Name</th>
<th class="head0">Description</th>
<th colspan="2" class="head1">Price</th>
<th class="head0">Qty</th>
<th class="head1">Total</th>
<th class="head0">Act</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="7" class="head1">GRAND TOTAL</th>
<th class="head0"><input type="text" name="total_qty" value="0" id="fixed" readonly="" /></th>
<th class="head1"><input type="text" name="grand_total" value="0" id="fixed" readonly="" /></th>
<th class="head0"></th>
</tr>
</tfoot>
<?php
$sql="select * from cart_po";
$query=mysql_query($sql);
while ($r=mysql_fetch_array($query)){
?>
<tbody>
<tr>
<td><?php echo $r['id_detail']; ?></td>
<td style="text-transform:capitalize;"><?php echo $r['product_name']; ?></td>
<td style="text-transform:uppercase;"><?php echo $r['product_code']; ?></td>
<td style="text-transform:capitalize;"><?php echo $r['design']; ?></td>
<td><?php echo $r['description']; ?></td>
<td ><input type="text" name="price[]" value='<?php echo $r['price']; ?>' onkeyup="grandTotal()" id="fixed"class="price" /></td>
<td style="text-align: center;">x</td>
<td ><input type="text" name="qty[]" value='0' id="fixed" onkeyup="grandTotal()" class="qty"/></td>
<td align="right"><input type="text" name="total[]" value="0" onkeyup="grandTotal()" id="fixed" class="total" readonly="total[]" /></td>
<td ><a href="home.php?source=delete-cart-po&code=<?php echo $r['product_code'];?>" onclick='return confirm("Are you sure to delete this data?");'><img src="images/icons/default/trash.png" title="Delete Data" /></a></td>
</tr>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".price").keyup(function(){
var total = $(this).parent().next().next().next().find('.total');
var qty = $(this).parent().next().next().find('.qty');
$(total).val($(this).val() * $(qty).val());
});
$(".qty").keyup(function(){
var total = $(this).parent().next().find('.total');
var price = $(this).parent().prev().prev().find('.price');
$(total).val($(this).val() * $(price).val());
});
});
function grandTotal(){
var total = 0;
var qty = 0;
$('.total').each(function(){
total += parseFloat($(this).val());
});
$('.qty').each(function(){
qty += parseFloat($(this).val());
});
$('input[name="grand_total"]').val(total);
$('input[name="total_qty"]').val(qty);
}
</script>
<?php }?>
</tbody>
</table>
function grandTotal(){
var total = 0;
var qty = 0;
console.log($('.total')); //tambahkan ini untuk melihat berapa element dengan class="total"
$('.total').each(function(){
console.log($(this).val()); // tambahkan ini melihat nilai dari text box total
total += parseFloat($(this).val());
});
$('.qty').each(function(){
qty += parseFloat($(this).val());
});
$('input[name="grand_total"]').val(total);
$('input[name="total_qty"]').val(qty);
}