Script:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form Pemesanan</title>
function diskon(){
var total = parseInt(document.pemesanan.total.value);
var diskon = 0;
if(total >= 50000){
diskon = 10000;
}
document.pemesanan.diskon.value = diskon;
}
function totalHarga(){
var harga;
var pesanan;
var total = 0;
for(i = 0; i < 10; i += 2){
harga = parseInt(document.pemesanan[i].value);
pesanan = parseInt(document.pemesanan[i + 1].value);
if(pesanan > 0){
total = total + (harga * pesanan);
}
document.pemesanan.total.value = total;
}
}
function jumlahBayar(){
var total = parseInt(document.pemesanan.total.value);
var diskon = parseInt(document.pemesanan.diskon.value);
var bayar = total - diskon;
document.pemesanan.bayar.value = bayar;
}
function proses(){
totalHarga();
diskon();
jumlahBayar();
}
function reset(){
var elemen = document.pemesanan;
elemen.pesan1.value = "";
elemen.pesan2.value = "";
elemen.pesan3.value = "";
elemen.pesan4.value = "";
elemen.pesan5.value = "";
elemen.total.value = "";
elemen.diskon.value = "";
elemen.bayar.value = "";
}
</script>
</head>
<body>
<h2>DEPOT NIKMAT</h2>
<br>
<form name="pemesanan" action="#">
<table border="1" cellspacing="0">
<tr>
<th>No.</th>
<th>Makanan / Minuman</th>
<th>Harga</th>
<th>Pesan</th>
</tr>
<tr>
<td>1</td>
<td>Nasi Goreng Lengkap</td>
<td>@<input type="text" name="harga1" value="12000" onchange="proses()"/></td>
<td><input type="text" name="pesan1" onchange="proses()"/></td>
</tr>
<tr>
<td>2</td>
<td>Nasi Goreng Kambing Spesial</td>
<td>@<input type="text" name="harga2" value="15000" onchange="proses()"/></td>
<td><input type="text" name="pesan2" onchange="proses()"/></td>
</tr>
<tr>
<td>3</td>
<td>Nasi Goreng Seafood</td>
<td>@<input type="text" name="harga3" value="12500" onchange="proses()"/></td>
<td><input type="text" name="pesan3" onchange="proses()"/></td>
</tr>
<tr>
<td>4</td>
<td>Es Degan</td>
<td>@<input type="text" name="harga4" value="2500" onchange="proses()"/></td>
<td><input type="text" name="pesan4" onchange="proses()"/></td>
</tr>
<tr>
<td>5</td>
<td>Es Campur</td>
<td>@<input type="text" name="harga5" value="6000" onchange="proses()"/></td>
<td><input type="text" name="pesan5" onchange="proses()"/></td>
</tr>
<tr>
<td colspan="3" align="right">Jumlah Total</td>
<td><input type="text" name="total" readonly /></td>
</tr>
<tr>
<td colspan="3" align="right">Diskon</td>
<td><input type="text" name="diskon" readonly /></td>
</tr>
<tr>
<td colspan="3" align="right">Jumlah Dibayar</td>
<td><input type="text" name="bayar" readonly /></td>
</tr>
</table>
<br>
<input type="button" name="Batal" value="Batal" onclick="reset()"/>
</form>
<br>
</html>
HASIL :
Tidak ada komentar:
Posting Komentar