Tuesday, March 1, 2011

tugas modul 5



---------------------------------------
tugas2.js
--------------------------------------
function hartot(){
    var harga;
    var pesan;
    var total = 0;
  
    for(i = 0; i < 10; i += 2){
        harga = parseInt(document.order[i].value);
        pesan = parseInt(document.order[i + 1].value);
      
        if(pesan > 0){
            total = total + (harga * pesan);
        }
      
        document.order.total.value = total;
    }
}

function diskon(){
    var total = parseInt(document.order.total.value);
    var diskon = 0;
  
    if(total >= 200000){
        diskon = 20 / 100 * total;
    }
    else if(total >= 100000){
        diskon = 10 / 100 * total;
    }
    else if(total >= 50000){
        diskon = 5 / 100 * total;
    }
  
    document.order.diskon.value = diskon;
}

function jumlahBayar(){
    var total = parseInt(document.order.total.value);
    var diskon = parseInt(document.order.diskon.value);
    var bayar = total - diskon;
  
    document.order.bayar.value = bayar;
}

function proses(){
    hartot();
    diskon();
    jumlahBayar();
}

function reset(){
    var elemen = document.order;
  
    elemen.pesan1.reset.value()
    elemen.pesan2.reset.value()
    elemen.pesan3.reset.value()
    elemen.pesan4.reset.value()
    elemen.pesan5.reset.value()
    elemen.total.reset.value()
    elemen.diskon.reset.value()
    elemen.bayar.reset.value()
}

--------------------------------------------
tugas02.html
--------------------------------------------
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>SUGENG RAWUH</title>
        <script language="JavaScript" type="text/javascript" src="tugas02.js"></script>
    </head>
    <body background = back.png>
    <center>
            <div class="title"><h2> <font SIXE="40" face = "Comic Sans MS" color = yellow> KEDAI SEDERHANA DAN SEADANYA </font></h2></div>
            <form name="order" action="#">
                <table border="1" bgcolor=white>
                    <tr>
                        <th>No</th>
                        <th>Makanan / Minuman</th>
                        <th>Harga</th>
                        <th>Pesan</th>
                    </tr>
                    <tr>
                        <td>1</td>
                        <td>MARTABAK TELOR BAKRIE</td>
                        <td>@<input type="text" name="har1" value="20000" onchange="proses()" readonly /></td>
                        <td><input type="text" name="pesan1" onchange="proses()"/></td>
                    </tr>
                    <tr>
                        <td>2</td>
                        <td>TERANG BULAN BESOES</td>
                        <td>@<input type="text" name="har2" value="18000" onchange="proses()" readonly /></td>
                        <td><input type="text" name="pesan2" onchange="proses()"/></td>
                    </tr>
                    <tr>
                        <td>3</td>
                        <td>ROTI BAKAR GAYUS</td>
                        <td>@<input type="text" name="har3" value="15000" onchange="proses()" readonly /></td>
                        <td><input type="text" name="pesan3" onchange="proses()"/></td>
                    </tr>
                    <tr>
                        <td>4</td>
                        <td>ES JUICE NH</td>
                        <td>@<input type="text" name="har4" value="7000" onchange="proses()" readonly /></td>
                        <td><input type="text" name="pesan4" onchange="proses()"/></td>
                    </tr>
                    <tr>
                        <td>5</td>
                        <td>ONDE-ONDE PSSI</td>
                        <td>@<input type="text" name="har5" value="5000" onchange="proses()" readonly /></td>
                        <td><input type="text" name="pesan5" onchange="proses()"/></td>
                    </tr>
                    <tr>
                        <td colspan="3" align="right">Jumlah Total</td>
                        <td><input type="text" name="total" readonly /></td>
                    </tr>
                    <tr>
                        <td colspan="3" align="right">Diskon</td>
                        <td><input type="text" name="diskon" readonly /></td>
                    </tr>
                    <tr>
                        <td colspan="3" align="right">Jumlah Dibayar</td>
                        <td><input type="text" name="bayar" readonly /></td>
                    </tr>
                </table>
                <br>
                <input type="button" name="batal" value="Batal" onclick="reset()"/>
            </form>
    </center>
    </body>
</html>