Tugas Praktikum
Script
hitungpesan.js
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 diskon(){
var total = parseInt(document.pemesanan.total.value);
var diskon = 0;
if(total >= 100000){
diskon = 20 / 100 * total;
}
else if(total >= 50000){
diskon = 10 / 100 * total;
}
else if(total >= 25000){
diskon = 5 / 100 * total;
}
document.pemesanan.diskon.value = diskon;
}
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 = "";
}
pesan.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form Pemesanan</title>
<script language="JavaScript" type="text/javascript" src="hitungpesan.js"></script>
</head>
<body><center>
<div class="title"><h2>Form Pemesanan Berbasis JavaScript</h2></div>
<section>
<form name="pemesanan" action="#">
<table border="1">
<tr>
<th>No</th>
<th>Makanan / Minuman</th>
<th>Harga</th>
<th>Pesan</th>
</tr>
<tr>
<td>1</td>
<td>Bakso Istimewa</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>Soto Spesial</td>
<td>@<input type="text" name="harga2" value="10000" onchange="proses()"/></td>
<td><input type="text" name="pesan2" onchange="proses()"/></td>
</tr>
<tr>
<td>3</td>
<td>Mie Ayam Super</td>
<td>@<input type="text" name="harga3" value="15000" 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="5000" 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="7000" 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="Reset" value="reset" onclick="reset()"/>
</form>
</section>
</center>
</body>
</html>
Hasil Tampilan
Tidak ada komentar:
Posting Komentar