Pengaturan

Gambar

Lainnya

Tentang KASKUS

Pusat Bantuan

Hubungi Kami

KASKUS Plus

© 2024 KASKUS, PT Darta Media Indonesia. All rights reserved

mpuyishereAvatar border
TS
mpuyishere
[ASK]HELP - Cara mengambil data looping di javascript dari database
Permisi mastah, ane mau minta tolong.
Ane mau ngambil data dari database ke javascript yang berupa integer kemudian data tersebut di kalkulasi.
Data hasil kalkulasi akan muncul seketika disamping kolom inputan tiap row.

ini gambar dari tabel data dan hasil kalkulasi :
[ASK]HELP - Cara mengambil data looping di javascript dari database

nah yang jadi masalah yaitu javascript untuk hitung kalkulasi tidak berfungsi pada row ke 2 dan seterusnya.

ini script saya :
Code:
<?php
//file connection to connect database
include "connection.php";
$i = 0;

$sql = mysql_query('SELECT * FROM product');
$total_row = mysql_num_rows($sql);

$no = 1;
?>

<html>
<head>
<title>How to show looping data array from database with javascript</title>
[removed][removed]
</head>
<body>
<center>
<h2>How to calculate looping data array from database with javascript</h2>
<table border="1" width="70%">
<form action="" method="post">
<thead>
<tr>
<th>No</th>
<th>Product Name</th>
<th>Price / pcs</th>
<th>Qty</th>
<th>Disc %</th>
<th>Total</th>
</tr>
</thead>
<?php
while ($row = mysql_fetch_array($sql)){
?>
<tbody>
<tr>
<td width="5"><input type="text" id="no" name="no" size="5" readonly="readonly" value="<?php echo $no++;?>"></td>
<td width="50"><input type="text" disabled="disable" id="product" name="product" size="50" value="<?php echo $row['name_product'];?>"></td>
<td align="right"><center><input type="text" name="price" id="price" value="<?php echo $row['price']; ?>"></center></td>
<td><center><input type="text" name="qty" id="qty"></center></td>
<td><center><input type="text" name="disc" id="disc" value="<?php echo $row['disc']; ?>"></center></td>
<td><center><input type="text" disabled="disable" id="total" name="total"></center></td>
</tr>
</tbody>
<?php } ?>
</form>
</table>
</center>

[removed]
$(document).ready(function() {
$('#disc').keyup(function(){
<!-- Ambil nilai bayar dan diskon !-->
var bayar=parseInt($('#price').val());
var kuantiti=parseInt($('#qty').val());
var diskon=parseInt($('#disc').val());

<!-- Perhitungan bayar-(diskon/100 x bayar) !-->
var total_bayar=(bayar*kuantiti)-(diskon/100)*(bayar*kuantiti);
$('#total').val(total_bayar);
});
});
[removed]
</body>
</html>
nona212
nona212 memberi reputasi
1
7.2K
7
GuestAvatar border
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Urutan
Terbaru
Terlama
GuestAvatar border
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Komunitas Pilihan