<HTML>
<HEAD><TITLE>Latihan Percabangan JavaScript</TITLE></HEAD>
<BODY>
<SRCRIPT language="JavaScript">
<!--
function hitungtotal()
{
var nama = (document.fform.inama.value);
var tujuan = (document.fform.itujuan.value);
var jumlahpaket = parseFloat (document.fform.ijumlah.value);
var ht = 0.0;
var sub = 0.0;
var diskon = 0.0;
var total = 0.0;
if (tujuan=="jakarta")
{
ht =10000;
}
else if (tujuan=="Yogyakarta")
{
ht =5000;
}
else
{
ht =20000;
}
sub = jumlahpaket*ht;
if (document.fform.imember.checked==true)
{
diskon =0.10*sub;
}
else
{
diskon =0.0;
}
total = sub-diskon;
document.fform.otiket.value=eval(ht);
document.fform.osub.value=eval(sub);
document.fform.odiskon.value=eval(diskon);
document.fform.ototal.value=eval(total);
//gunakan untuk mengecek !!! alert (total);
}
//--></SCRIPT>
<FORM NAME ="fform">
<table border="1" align="center"width="70%">
<tr>
<td width=100%" colspan="2"><H2 align="center">Jasa Kiriman Paket</H2></td>
</tr>
<tr>
<td width="50%"><PRE>
Nama :<input type="text" size="20" name="inama">
Tujuan :<select name="itujuan" size="1">
<option value="Jakarta">Jakarta</option>
<option value="Yogyakarta">Yogyakarta</option>
<option value="Semarang">Semarang</option>
</select>
Jumlah tiket :<input type="text" size="11" name="ijumlah">
Member :<input type="checkbox" name="imember">ya</td></pre>
<td width="50%"><pre>
Harga Tiket :<input type="text" size="10" name="otiket">
Sub Total :<input type="text" size="10" name="osub">
Diskon :<input type="text" size="10" name="odiskon">
Total Bayar :<input type="text" size="10" name="otatal"></td><pre>
</tr>
<tr>
<td width="100%" colspan="2">
<center>
<INPUT TYPE="button" value="Hitung" onclick="hitungtotal()">
<INPUT TYPE="reset" value="ulang">
</center></td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
<HEAD><TITLE>Latihan Percabangan JavaScript</TITLE></HEAD>
<BODY>
<SRCRIPT language="JavaScript">
<!--
function hitungtotal()
{
var nama = (document.fform.inama.value);
var tujuan = (document.fform.itujuan.value);
var jumlahpaket = parseFloat (document.fform.ijumlah.value);
var ht = 0.0;
var sub = 0.0;
var diskon = 0.0;
var total = 0.0;
if (tujuan=="jakarta")
{
ht =10000;
}
else if (tujuan=="Yogyakarta")
{
ht =5000;
}
else
{
ht =20000;
}
sub = jumlahpaket*ht;
if (document.fform.imember.checked==true)
{
diskon =0.10*sub;
}
else
{
diskon =0.0;
}
total = sub-diskon;
document.fform.otiket.value=eval(ht);
document.fform.osub.value=eval(sub);
document.fform.odiskon.value=eval(diskon);
document.fform.ototal.value=eval(total);
//gunakan untuk mengecek !!! alert (total);
}
//--></SCRIPT>
<FORM NAME ="fform">
<table border="1" align="center"width="70%">
<tr>
<td width=100%" colspan="2"><H2 align="center">Jasa Kiriman Paket</H2></td>
</tr>
<tr>
<td width="50%"><PRE>
Nama :<input type="text" size="20" name="inama">
Tujuan :<select name="itujuan" size="1">
<option value="Jakarta">Jakarta</option>
<option value="Yogyakarta">Yogyakarta</option>
<option value="Semarang">Semarang</option>
</select>
Jumlah tiket :<input type="text" size="11" name="ijumlah">
Member :<input type="checkbox" name="imember">ya</td></pre>
<td width="50%"><pre>
Harga Tiket :<input type="text" size="10" name="otiket">
Sub Total :<input type="text" size="10" name="osub">
Diskon :<input type="text" size="10" name="odiskon">
Total Bayar :<input type="text" size="10" name="otatal"></td><pre>
</tr>
<tr>
<td width="100%" colspan="2">
<center>
<INPUT TYPE="button" value="Hitung" onclick="hitungtotal()">
<INPUT TYPE="reset" value="ulang">
</center></td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
0 comments:
Posting Komentar