Di modul kelima kita mencoba untuk membuat sebuah aplikasi kalkulator yang bisa diakses lewat internet, tampilan visual dari outputnya sebagai berikut :
<!DOCTYPE html>
<head>
<title>Praktikum 5</title>
</head>
<body>
<html>
<title></title>
<script language="JavaScript" type="text/javascript">
function pemesanan(){
var nota = document.form2;
var hargaBakso = 12000 * eval(nota.hrgBakso.value);
var hargaSoto = 10000 * eval(nota.hrgSoto.value);
var hargaMie = 15000 * eval(nota.hrgMie.value);
var hargaDegan = 5000 * eval(nota.hrgDegan.value);
var hargaCampur = 7000 * eval(nota.hrgCampur.value);
var TotalHarga = hargaBakso + hargaSoto + hargaMie + hargaDegan + hargaCampur;
if (TotalHarga > 50000){
nota.Total.value = TotalHarga;
nota.Diskon.value = 10000;
nota.Bayar.value = TotalHarga - eval(nota.Diskon.value);
} else {
nota.Total.value = TotalHarga;
nota.Diskon.value = 0;
nota.Bayar.value = TotalHarga - eval(nota.Diskon.value);
}
}
function resetForm(){
document.form2.reset();
}
</script>
<H2>Form Pemesanan Makan dan Minum</H2>
<form name="form2" action="#">
<table border="1px">
<tr bgcolor="#990000">
<th>No</th>
<th>Makanan/Minuman</th>
<th>Harga</th>
<th>Pesan</th>
</tr>
<tr bgcolor="#990000">
<td width="20">1</td>
<td width="190">Bakso Istimewa</td>
<td width="90"> @ <input type="text" name="bakso" value="12000" size="7" readonly="readonly"/></td>
<td width="160"><input type="text" name="hrgBakso" value="0" onFocus="this.select()" onChange="pemesanan()"/></td>
</tr>
<tr bgcolor="#990000">
<td>2</td>
<td>Soto Spesial</td>
<td> @ <input type="text" name="soto" value="10000" size="7" readonly="readonly"/></td>
<td><input type="text" name="hrgSoto" value="0" onFocus="this.select()" onChange="pemesanan()"/></td>
</tr>
<tr bgcolor="#990000">
<td>3</td>
<td>Mie Ayam Super</td>
<td> @ <input type="text" name="mie" value="15000" size="7" readonly="readonly"/></td>
<td><input type="text" name="hrgMie" value="0" onFocus="this.select()" onChange="pemesanan()"/></td>
</tr>
<tr bgcolor="#990000">
<td>4</td>
<td>Es Degan</td>
<td> @ <input type="text" name="degan" value="7000" size="7" readonly="readonly"/></td>
<td><input type="text" name="hrgDegan" value="0" onFocus="this.select()" onChange="pemesanan()"/></td>
</tr>
<tr bgcolor="#990000">
<td>5</td>
<td>Es Campur</td>
<td> @ <input type="text" name="campur" value="7000" size="7" readonly="readonly"/></td>
<td><input type="text" name="hrgCampur" value="0" onFocus="this.select()" onChange="pemesanan()"/></td>
</tr>
<tr bgcolor="#990000">
<td colspan="3" align="right">Jumlah Total</td>
<td><input type="text" name="Total" readonly="readonly" /></td>
</tr>
<tr bgcolor="#990000">
<td colspan="3" align="right">Diskon</td>
<td><input type="text" name="Diskon" readonly="readonly"/></td>
</tr>
<tr bgcolor="#990000">
<td colspan="3" align="right">Jumlah Dibayar</td>
<td><input type="text" name="Bayar" readonly="readonly" align="right"/></td>
</tr>
</table><br/>
<input type="button" value="CLEAR" onClick="resetForm()" />
</form>
</body>
</html></em>
</body>
</html>
0 comments
Posting Komentar