Mar 1, 2011

Tugas Praktikum Modul 5

Script untuk javaScript:
function HargaTotal()
var harga;
var pesan;
var total = 0;
for(i = 0; i < 12; i += 2){
harga = parseInt(document.pemesanan[i].value);
pesan = parseInt(document.pemesanan[i + 1].value);

if(pesan > 0){
total = total + (harga * pesan);
}
document.pemesanan.total.value = total;
}
}

function Potongan(){
var total = parseInt(document.pemesanan.total.value);
var diskon = 0;
if(total >= 100000){
diskon = 7.5 / 100 * total;
}
else if(total >= 50000){
diskon = 5 / 100 * total;
}
else if(total >= 25000){
diskon = 2.5 / 100 * total;
}
document.pemesanan.diskon.value = diskon;
}

function TotalBayar(){
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(){
HargaTotal();
Potongan();
TotalBayar();
}

function clear(){
var elemen = document.pemesanan;
elemen.pesan1.value = "";
elemen.pesan2.value = "";
elemen.pesan3.value = "";
elemen.pesan4.value = "";
elemen.pesan5.value = "";
elemen.pesan6.value = "";
elemen.total.value = "";
elemen.diskon.value = "";
elemen.bayar.value = "";
}
Script untuk html:
<!DOCTYPEhtml>
<html lang="en">
<head>
<title>Form Pemesanan</title>
<script language="JavaScript" type="text/javascript" src="pesan.js"></script>

</head>
<body>
<hr width="505px" size="7" color="green" align="left">
<h2><font color=red><blink> Form Pemesanan Berbasis Java Script</blink></font></h2>
<hr width="505px" size="7" color="green" align="left">
<form name="pemesanan" action="#">
<table border="3">
<tr bgcolor="purple">
<th>No</th>
<th>Makanan / Minuman</th>
<th>Harga</th>
<th>Pesan</th>
</tr>
<tr>
<td align="center">1</td>
<td>Bakso Bakar</td>
<td>@<input type="text" name="harga1" value="12000" onchange="proses()" /></td>
<td><input type="text" name="pesan1" onchange="proses()" /></td>
</tr>
<tr>
<td align="center">2</td>
<td>Soto Babat</td>
<td>@<input type="text" name="harga2" value="10000" onchange="proses()" /></td>
<td><input type="text" name="pesan2" onchange="proses()" /></td>
</tr>
<tr>
<td align="center">3</td>
<td>Mie Ayam Putra Solo</td>
<td>@<input type="text" name="harga3" value="15000" onchange="proses()" /></td>
<td><input type="text" name="pesan3" onchange="proses()" /></td>
</tr>
<tr>
<td align="center">4</td>
<td>Es Degan Ijo</td>
<td>@<input type="text" name="harga4" value="5000" onchange="proses()" /></td>
<td><input type="text" name="pesan4" onchange="proses()" /></td>
</tr>
<tr>
<td align="center">5</td>
<td>Es Campur Buah</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" bgcolor=violet>Jumlah Total</td>
<td><input type="text" name="total" readonly /></td>
</tr>
<tr>
<td colspan="3" align="right" bgcolor=violet>Diskon</td>
<td><input type="text" name="diskon" readonly /></td>
</tr>
<tr>
<td colspan="3" align="right" bgcolor=violet>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>
<font size="2px">
<b>Ketentuan Diskon :</b><br>
- Diskon 2.5% untuk Pemebelian diatas Rp 25.000,00<br>
- Diskon 5.0% untuk Pemebelian diatas Rp 50.000,00<br>
- Diskon 7.5% untuk Pemebelian diatas Rp 100.000,00<br>
<hr width="505px" size="7" color="blue" align="left">
</body>
</html>
Gambar Tampilan:

0 komentar:

Post a Comment