Selasa, 01 Maret 2011

Pemesanan Makanan/Minuman

MEMBUAT APLIKASI FORM PEMESANAN MAKANAN/MINUMAN



JAVASCRIPT
function harga(){
    var warung = document.form1;
    var hargaBakso = 12000 * eval(warung.Bakso.value);
    var hargaSoto = 10000 * eval(warung.Soto.value);
    var hargaMie = 15000 * eval(warung.Mie.value);
    var hargaDegan = 5000 * eval(warung.Degan.value);
    var hargaCampur = 7000 * eval(warung.Campur.value);
    var jumlahTotal = hargaBakso + hargaSoto + hargaMie + hargaDegan + hargaCampur;
        if (jumlahTotal > 50000){
            warung.Total.value = jumlahTotal;
            warung.Diskon.value = 10000;
            warung.Bayar.value = jumlahTotal - eval(warung.Diskon.value);
        } else {
    warung.Total.value = jumlahTotal;
    warung.Diskon.value = 0;
    warung.Bayar.value = jumlahTotal - eval(warung.Diskon.value);
    }
}

function resetForm(){
    document.form1.reset();
}



HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Praktikum</title>
    <script type="text/javascript" src="warung.js"></script>
</head>

<body>

<h3>Form Pemesanan Berbasis JavaScript</h3>
<form name="form1" action="#">
<table border="1px">

<tr>
    <th>No</th>
    <th>Makanan/Minuman</th>
    <th>Harga</th>
    <th>Pesan</th>
</tr>

<tr>
    <td width="15">1</td>
    <td width="200">Bakso Istimewa</td>
    <td width="100">@.<input type="text" name="bakso" value="12000" size="8" disabled="true"/></td>
    <td width="150"><input type="text" name="Bakso" size="20" value="0" onChange="harga()"/></td>
</tr>

<tr>
    <td width="15">2</td>
    <td width="200">Soto Spesial</td>
    <td width="100">@.<input type="text" name="soto" value="10000" size="8" disabled="true"/></td>
    <td width="150"><input type="text" name="Soto" size="20" value="0" onChange="harga()"/></td>
</tr>

<tr>
    <td width="15">3</td>
    <td width="200">Mie Ayam Super</td>
    <td width="100">@.<input type="text" name="mie" value="15000" size="8" disabled="true"/></td>
    <td width="150"><input type="text" name="Mie" size="20" value="0" onChange="harga()"/></td>
</tr>

<tr>
    <td width="15">4</td>
    <td width="200">Es Degan</td>
    <td width="100">@.<input type="text" name="degan" value="5000" size="8" disabled="true"/></td>
    <td width="150"><input type="text" name="Degan" size="20" value="0" onChange="harga()"/></td>
</tr>

<tr>
    <td width="15">5</td>
    <td width="200">Es Campur</td>
    <td width="100">@.<input type="text" name="campur" value="7000" size="8" disabled="true"/></td>
    <td width="150"><input type="text" name="Campur" size="20" value="0" onChange="harga()"/></td>
</tr>

<tr>
    <td colspan="3" align="right">Jumlah Total</td>
    <td>@.<input type="text" name="Total" size="17" disabled="true" /></td>
</tr>

<tr>
    <td colspan="3" align="right">Diskon</td>
    <td>@.<input type="text" name="Diskon" size="17" disabled="true" /></td>
</tr>

<tr>
    <td colspan="3" align="right">Jumlah Dibayar</td>
    <td>@.<input type="text" name="Bayar" disabled="true" size="17" align="right"/></td>
</tr>
</table><br/>

<input type="button" value="Batal" onClick="resetForm()" />
</form>

</body>
</html>






0 komentar:

Posting Komentar