Anda di halaman 1dari 2

<html> <head> <title> TUGAS </title> <script type="text/javascript"> function addRow(){ var kodePesanan = document.getElementById("kodePesanan"); var menuYangDipesan = document.

getElementById("menuYangDipesan"); var harga = document.getElementById("harga"); var jumlahPesanan = document.getElementById("jumlahPesanan"); var subTotal = document.getElementById("subTotal"); var totalHarga = document.getElementById("totalHarga"); var table = document.getElementById("data"); var rowCount = table.rows.length; var row = table.insertRow(rowCount); row.insertCell(0).innerHTML = kodePesanan.value; row.insertCell(1).innerHTML = menuYangDipesan.value; row.insertCell(2).innerHTML = harga.value; row.insertCell(3).innerHTML = jumlahPesanan.value; row.insertCell(4).innerHTML = harga.value*jumlahPesanan.value; var k=1; var total=0; for(var i=0;i<rowCount;i++) { total += parseInt(table.rows[k].cells[4].innerHTML, 10); k++; } totalHarga.value=total; if (lengthRestriction(kodePesanan, 4, 4)){ return true; } return false; } function lengthRestriction(kodePesanan, min, max){ var uInput = kodePesanan.value; if(uInput.length >= min && uInput.length <= max){ return true; } else { alert("kode pesanan hanya 4 digit"); kodePesanan.focus(); return false; } } function reset(){ var kodePesanan = document.getElementById("kodePesanan"); var menuYangDipesan = document.getElementById("menuYangDipesan"); var harga = document.getElementById("harga"); var jumlahPesanan = document.getElementById("jumlahPesanan"); var subTotal = document.getElementById("subTotal"); var totalHarga = document.getElementById("totalHarga"); kodePesanan.value = ""; menuYangDipesan.value = ""; harga.value = ""; jumlahPesanan.value = "";

subTotal.value = ""; totalHarga.value = ""; } </script> </head> <body onload="load()" text="black" bgcolor=""> <h3>INPUT</h3> <div id="myform"> <table> <tr> <td>Kode Pesanan</td><td>:</td> <td><input type="text" id="kodePesanan" maxlength="4"></td> </tr> <tr> <td>Menu yang dipesan</td><td>:</td> <td><input type="text" id="menuYangDipesan"></td> </tr> <tr> <td>Harga</td><td>:</td> <td><input type="text" id="harga"></td> </tr> <tr> <td>Jumlah Pesanan</td><td>:</td> <td><input type="text" id="jumlahPesanan"></td> </tr> <tr> <td><input type="submit" id="add" value="OK" onclick="javascript:addRow( ); sum(); addRow2();"> <input type="reset" id="clear" value="CANCEL" onClick="javascrip t:reset()"/></td> </tr> </table> </div> <h3>OUTPUT</h3> <div id="dataku"> <table width="500" id="data" border="1" cellpadding="2"> <tr align="center"> <th>Kode Pesanan</th> <th>Menu yang dipesan</th> <th>Harga</th> <th>Jumlah Pesanan</th> <th>Subtotal</th> </tr> </table> &nbsp; </div> <div id="sum"> <table id="data" border="1" cellpadding="2"> <tr> <th>Total Harga</th> <td><input type="text" id="totalHarga" size="20"/></td> </tr> </table> </div> </body> </html>