Cara mengenerate sel tabel secara fleksibel dapat kita lakukan dengan membuat dua buah file yang berektensi *.html dan *.php. Source Codenya seperti dibawah ini :
Source Code *.html :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<title>Tabel Generate</title>
<style type="text/css">
<!--
#a1 {
width: 180px;
height: 25px;
z-index: 1;
left: 285px;
top: 190px;
}
color: white;
.b1 {
font-weight: bold;
}
-->
</style>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function getmax() {
var R = parseInt(document.getElementById('JumlahRow').value);
var C = parseInt(document.getElementById('JumlahColum').value);
var X = parseInt(document.getElementById('JumlahCell').value);
var cellmax = document.getElementById('maxcells');
var total = 'N/A';
total = R * C;
cellmax.value = new String(total);
if (X > total)
{
alert('Cell Total Yang Anda Masukkan Terlalu Besar, Nilai Maksimum Cells = ' + total);
document.getElementById('CellsTotal').value = new String();
}
}
</script>
<form method="post" action="generate.php">
<h3 class="b1">Program Generate Sel Tabel Secara Fleksibel</h3>
<div>
<table width="300" border="0" bgcolor=blue>
<tr bgcolor="white">
<td width="120" style="text-align:center">Jumlah Baris</td>
<td width="189"><strong>= </strong>
<input name="JumlahRow" type="text" id="JumlahRow" onKeyUp="getmax();" onfocus="this.select();"/></td>
</tr>
<tr bgcolor="white">
<td style="text-align:center"><label>Jumlah Kolom</label></td>
<td><strong>= </strong>
<input name="JumlahColum" type="text" id="JumlahColum" onKeyUp="getmax();" onfocus="this.select();"/></td>
</tr>
<tr bgcolor="white">
<td style="text-align:center">Jumlah Sel Total </td>
<td><strong>= </strong>
<input name="JumlahCell" type="text" id="JumlahCell" onKeyUp="getmax();" onFocus="this.select();"/></td>
</tr>
<tr bgcolor="white">
<td style="text-align:center">Tampilkan Jumlah Maks Sel </td>
<td><strong>= </strong>
<input name="maxcells" type="text" id="maxcells" readonly="readonly" style="text-align:center"/></td>
</tr>
</table>
</div>
<div id="a1">
<input type="submit" name="Generate" value="Generate"/>
<input type="reset" name="Reset" value="Reset"/>
</div>
</form>
</body>
</html>
Source Code *.php :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<title>Hasil Generate</title>
</head>
<body>
<div align="center">
<?php
$rows = 1;
$columns = 1;
$cells = 1;
?>
<?php $rows = (int) $_POST["JumlahRow"]; ?>
<?php $columns = (int) $_POST["JumlahColum"]; ?>
<?php $cells = (int) $_POST["JumlahCell"]; ?>
<strong>Anda Membuat</strong> <?php echo $rows; ?> <em>baris,</em><br />
<strong>Anda Membuat</strong> <?php echo $columns; ?> <em>kolom,</em><br />
<strong>Dan Anda Menampilkan</strong> <?php echo $cells; ?> <em>sel tabel,</em><br />
<br />
<br />
<?php
$width = $columns * 75;
echo "<table width=".$width." border=1>";
$rw = 0;
$cel = 1;
while ($rw < $rows && $cel <= $cells)
{
echo "<tr>";
$cl = 0;
while ($cl < $columns)
{
if ($cel <= $cells)
{
echo "<td><div align=center>".$cel."</div></td>";
$cel++;
}
$cl++;
}
echo "</tr>";
$rw++;
}
echo "</table>";
?>
</div>
</body>
</html>
Tampilan programnya seperti dibawah ini :
Tampilan program setelah dieksekusi :
Selasa, 08 Maret 2011
Selasa, 01 Maret 2011
Praktikum 5-Warung Makan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Warung Makan Suka-Suka</title>
<script type="text/javascript" src="warung.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
</script><h3>PEMESANAN MAKANAN WARUNG SUKA-SUKA</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="15">1</td>
<td width="200">Bakso Istimewa</td>
<td width="90">@ <input type="text" name="bakso" value="Rp.12000" size="6" disabled="true"/></td>
<td width="110"><input type="text" name="Bakso" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>2</td>
<td>Soto Spesial</td>
<td>@ <input type="text" name="soto" value="Rp.10000" size="6" disabled="true"/></td>
<td><input type="text" name="Soto" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>3</td>
<td>Mie Ayam Super</td>
<td>@ <input type="text" name="mie" value="Rp.15000" size="6" disabled="true"/></td>
<td><input type="text" name="Mie" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>4</td>
<td>Es Degan</td>
<td>@ <input type="text" name="degan" value="Rp.5000" size="6" disabled="true"/></td>
<td><input type="text" name="Degan" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>5</td>
<td>Es Campur</td>
<td>@ <input type="text" name="campur" value="Rp.7000" size="6" disabled="true"/></td>
<td><input type="text" name="Campur" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td colspan="3" align="right">Jumlah Total</td>
<td>@.<input type="text" name="Total" size="10" disabled="true" /></td>
</tr>
<tr>
<td colspan="3" align="right">Diskon</td>
<td>@.<input type="text" name="Diskon" size="10" disabled="true" /></td>
</tr>
<tr>
<td colspan="3" align="right">Jumlah Dibayar</td>
<td>@.<input type="text" name="Bayar" disabled="true" size="10" align="right"/></td>
</tr>
</table><br/>
<input type="button" value="BATAL" onClick="resetForm()" />
</form>
</body>
</html>
--->> Buat file baru dengan nama warung.js
function hitungPesan(){
var nota = document.form2;
var hargaBakso = 12000 * eval(nota.Bakso.value);
var hargaSoto = 10000 * eval(nota.Soto.value);
var hargaMie = 15000 * eval(nota.Mie.value);
var hargaDegan = 5000 * eval(nota.Degan.value);
var hargaCampur = 7000 * eval(nota.Campur.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();
}
<html>
<head>
<title>Warung Makan Suka-Suka</title>
<script type="text/javascript" src="warung.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
</script><h3>PEMESANAN MAKANAN WARUNG SUKA-SUKA</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="15">1</td>
<td width="200">Bakso Istimewa</td>
<td width="90">@ <input type="text" name="bakso" value="Rp.12000" size="6" disabled="true"/></td>
<td width="110"><input type="text" name="Bakso" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>2</td>
<td>Soto Spesial</td>
<td>@ <input type="text" name="soto" value="Rp.10000" size="6" disabled="true"/></td>
<td><input type="text" name="Soto" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>3</td>
<td>Mie Ayam Super</td>
<td>@ <input type="text" name="mie" value="Rp.15000" size="6" disabled="true"/></td>
<td><input type="text" name="Mie" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>4</td>
<td>Es Degan</td>
<td>@ <input type="text" name="degan" value="Rp.5000" size="6" disabled="true"/></td>
<td><input type="text" name="Degan" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td>5</td>
<td>Es Campur</td>
<td>@ <input type="text" name="campur" value="Rp.7000" size="6" disabled="true"/></td>
<td><input type="text" name="Campur" size="14" value="0" onChange="hitungPesan()"/></td>
</tr>
<tr>
<td colspan="3" align="right">Jumlah Total</td>
<td>@.<input type="text" name="Total" size="10" disabled="true" /></td>
</tr>
<tr>
<td colspan="3" align="right">Diskon</td>
<td>@.<input type="text" name="Diskon" size="10" disabled="true" /></td>
</tr>
<tr>
<td colspan="3" align="right">Jumlah Dibayar</td>
<td>@.<input type="text" name="Bayar" disabled="true" size="10" align="right"/></td>
</tr>
</table><br/>
<input type="button" value="BATAL" onClick="resetForm()" />
</form>
</body>
</html>
--->> Buat file baru dengan nama warung.js
function hitungPesan(){
var nota = document.form2;
var hargaBakso = 12000 * eval(nota.Bakso.value);
var hargaSoto = 10000 * eval(nota.Soto.value);
var hargaMie = 15000 * eval(nota.Mie.value);
var hargaDegan = 5000 * eval(nota.Degan.value);
var hargaCampur = 7000 * eval(nota.Campur.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();
}
Praktikum 5-Studi Kasus
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kalkulator Sederhana</title>
<script type="text/javascript" src="rumus.js"></script>
</head>
<p>
<h2>Program Kalkulator Sederhana</h2>
</p>
<body>
<form name="form1" action="#"><input type="text" name="a"/>
<select name="opt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" name="b"/>
<input type="button" value="=" onClick="hitung()"/>
<input type="text" name="hasil" disabled="true"/><br/>
<input type="button" value="clear" onClick="resetForm()"/>
</form>
</body>
</html>
---->> Buat file baru dengan nama rumus.js
function hitung(){
var myForm = document.form1;
var a=eval(myForm.a.value);
var b=eval(myForm.b.value);
var pil= myForm.opt.value;
if (pil == "+") {
var c = a + b;
}else if (pil == "-") {
var c = a - b;
} else if (pil == "*") {
var c = a * b;
} else if (pil == "/") {
var c = a / b;
}
myForm.hasil.value = c;
}
function resetForm(){
document.form1.reset();
}
//-->
<html lang="en">
<head>
<title>Kalkulator Sederhana</title>
<script type="text/javascript" src="rumus.js"></script>
</head>
<p>
<h2>Program Kalkulator Sederhana</h2>
</p>
<body>
<form name="form1" action="#"><input type="text" name="a"/>
<select name="opt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" name="b"/>
<input type="button" value="=" onClick="hitung()"/>
<input type="text" name="hasil" disabled="true"/><br/>
<input type="button" value="clear" onClick="resetForm()"/>
</form>
</body>
</html>
---->> Buat file baru dengan nama rumus.js
function hitung(){
var myForm = document.form1;
var a=eval(myForm.a.value);
var b=eval(myForm.b.value);
var pil= myForm.opt.value;
if (pil == "+") {
var c = a + b;
}else if (pil == "-") {
var c = a - b;
} else if (pil == "*") {
var c = a * b;
} else if (pil == "/") {
var c = a / b;
}
myForm.hasil.value = c;
}
function resetForm(){
document.form1.reset();
}
//-->
Langganan:
Postingan (Atom)