program javascript untuk mengkodisikan
<html>
<head>
<title>javascript</title>
<script type="text/javascript">
function hitung(){
var jumlah = parseInt(document.penjualan.jumlah.value);
var barang = document.penjualan.barang.value;
var harga=0.0;
if(barang == "sabun"){
harga = 3000;
}else if(barang == "parfum"){
harga = 20000;
}else{
harga = 5000;
}
var member = document.penjualan.member.checked;
var total = harga * jumlah;
if(member == true){
total = total * (20/100)
}
alert("harga = "+total);
}
</script>
</head>
<body>
<form name="penjualan">
<table>
<tr>
<td>masukkan jumlah barang</td>
<td><input type="text" name="jumlah"></td>
</tr>
<tr>
<td>pilih nama barang</td>
<td>
<select name="barang">
<option value="sabun">sabun</option>
<option value="parfum">parfum</option>
<option value="shampo">shampo</option>
</select>
</td>
</tr>
<tr>
<td>member</td>
<td><input type="checkbox" name="member"></td>
</tr>
<tr>
<td>total harga</td>
<td><input type="text" name="hasil" value="0"></td>
</tr>
<tr>
<td>
<input type="button" value="proses" onclick="hitung()">
</td>
</td>
</table>
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar