Sunday, March 6, 2011

apLikasi iN weB..

Pembuatan aplikasi form, masih menggunakan perpaduan DHTML dan java script.
Hasilnya seperti:


Codenya:

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

<head>

<title>Makan</title>

</head>

<body>

<script language="JavaScript" type="text/javascript">

function hitungPesan(){

var nota = document.form2;

var hargaBakso = 12000 * eval(nota.qBakso.value);

var hargaSoto = 10000 * eval(nota.qSoto.value);

var hargaMie = 15000 * eval(nota.qMie.value);

var hargaDegan = 5000 * eval(nota.qDegan.value);

var hargaCampur = 7000 * eval(nota.qCampur.value);

var jumlahTotal = hargaBakso + hargaSoto + hargaMie + hargaDegan + hargaCampur;

if (jumlahTotal > 50000){

    nota.Total.value = jumlahTotal;

    nota.Diskon.value = 10000;

    nota.Bayar.value = jumlahTotal - eval(nota.Diskon.value);

 } else {

    nota.Total.value = jumlahTotal;

    nota.Diskon.value = 0;

    nota.Bayar.value = jumlahTotal - eval(nota.Diskon.value);

 }

}

function resetForm(){

document.form2.reset();

}
</script>

<h3>Form Pemesanan Berbasis JavaScript</h3>

<form name="form2" action="#">

<table border="1px">

<tr>

    <th>No</th>

    <th>Makanan/Minuman</th>

    <th>Harga</th>

    <th>Pesan</th>

</tr>

<tr>

    <td width="15px">1</td>

    <td width="200px">Bakso Istimewa</td>

    <td width="85px" bgcolor="gray">&#64; <input type="text" name="bakso" value="12000" size="6" disabled="true"/></td>

    <td width="150px"><input type="text" name="qBakso" value="0" onChange="hitungPesan()"/></td>

</tr>

<tr>

    <td>2</td>

    <td>Soto Spesial</td>

    <td bgcolor="gray">&#64; <input type="text" name="soto" value="10000" size="6" disabled="true"/></td>

    <td><input type="text" name="qSoto" value="0" onChange="hitungPesan()"/></td>

</tr>

<tr>

    <td>3</td>

    <td>Mie Ayam Super</td>

    <td bgcolor="gray">&#64; <input type="text" name="mie" value="15000" size="6" disabled="true"/></td>

    <td><input type="text" name="qMie" value="0" onChange="hitungPesan()"/></td>

</tr>

<tr>

    <td>4</td>

    <td>Es Degan</td>

    <td bgcolor="gray">&#64; <input type="text" name="degan" value="5000" size="6" disabled="true"/></td>

    <td><input type="text" name="qDegan" value="0" onChange="hitungPesan()"/></td>

</tr>

<tr>

    <td>5</td>

    <td>Es Campur</td>

    <td bgcolor="gray">&#64; <input type="text" name="campur" value="7000" size="6" disabled="true"/></td>

    <td><input type="text" name="qCampur" value="0" onChange="hitungPesan()"/></td>

</tr>

<tr bgcolor="red">

    <td colspan="3" align="right">Jumlah Total</td>

    <td><input type="text" name="Total" disabled="true" /></td>

</tr>

<tr bgcolor="yellow">

    <td colspan="3" align="right">Diskon</td>

    <td><input type="text" name="Diskon" disabled="true" /></td>

</tr>

<tr bgcolor="green">

    <td colspan="3" align="right">Jumlah Dibayar</td>

    <td><input type="text" name="Bayar" disabled="true" align="right"/></td>

</tr>

</table>

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

</form>

</body>

</html>

No comments:

Post a Comment