Berikut adalah kode html-nya, simpan dengan nama tablegenerate.html <br /> <br /><em><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <br /><title>Table Generate</title> <br /><style type="text/css"> <br /><!-- <br />#apDiv1 { <br /> width:182px; <br /> height:30px; <br /> z-index:1; <br /> left: 284px; <br /> top: 189px; <br />} <br /> color: #00ff00; <br />.style1 { <br /> font-weight: bold; <br /> text-align: center; <br />} <br />--> <br /></style> <br /><body background="pic.jpg"> <br /><script language="JavaScript" type="text/javascript"> <br />function getmax() { <br /> var R = parseInt(document.getElementById('JumlahRow').value); <br /> var C = parseInt(document.getElementById('JumlahColum').value); <br /> var X = parseInt(document.getElementById('JumlahCell').value); <br /> var cellmax = document.getElementById('maxcells'); <br /> var total = 'N/A'; <br /> total = R * C; <br /> cellmax.value = new String(total); <br /> if (X > total) <br /> { <br /> alert('Cell Total Yang Anda Masukkan Terlalu Besar, Nilai Maksimum Cells = ' + total); <br /> document.getElementById('CellsTotal').value = new String(); <br /> } <br />} <br /> <br /></script> <br /><form method="post" action="proses.php"> <br /> <h3 class="style1">Tabel Fleksibel</h3> <br /> <div> <br /> <table width="300" border="0" bgcolor="#00ff00"> <br /> <tr bgcolor="#ffff00"> <br /> <td width="120" style="text-align:left">Rows</td> <br /> <td width="189"><strong>= </strong> <br /> <input name="JumlahRow" type="text" id="JumlahRow" onKeyUp="getmax();" onfocus="this.select();"/></td> <br /> </tr> <br /> <tr bgcolor="#ffff00"> <br /> <td style="text-align:left"><label>Columns</label></td> <br /> <td><strong>= </strong> <br /> <input name="JumlahColum" type="text" id="JumlahColum" onKeyUp="getmax();" onfocus="this.select();"/></td> <br /> </tr> <br /> <tr bgcolor="#ffff00"> <br /> <td style="text-align:left">Total Cells </td> <br /> <td><strong>= </strong> <br /> <input name="JumlahCell" type="text" id="JumlahCell" onKeyUp="getmax();" onFocus="this.select();"/></td> <br /> </tr> <br /> <tr bgcolor="#ffff00"> <br /> <td style="text-align:left">Max Cells </td> <br /> <td><strong>= </strong> <br /> <input name="maxcells" type="text" id="maxcells" readonly="readonly" style="text-align:left"/></td> <br /> </tr> <br /> </table> <br /> </div> <br /> <div id="apDiv1"> <br /> <input type="submit" name="Generate" value="Generate"/><input type="reset" name="Reset" value="Reset"/> <br /> </div> <br /></form> <br /></body> <br /></em> <br /> Dan berikut kode php, simpan dengan nama proses.php <br /><em><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <br /><title>Hasilnya</title> <br /><body> <br /><div align="center"> <br /> <?php <br />$rows = 1; <br />$columns = 1; <br />$cells = 1; <br />?> <br /> <br /> <?php $rows = (int) $_POST["JumlahRow"]; ?> <br /> <?php $columns = (int) $_POST["JumlahColum"]; ?> <br /> <?php $cells = (int) $_POST["JumlahCell"]; ?> <br /> <br /> <strong>Anda Memilih</strong> <?php echo $rows; ?> <em>rows,</em><br /> <br /> <strong>Anda Memilih</strong> <?php echo $columns; ?> <em>columns,</em><br /> <br /> <strong>Dan Anda Membutuhkan</strong> <?php echo $cells; ?> <em>cells,</em><br /> <br /> <br /> <br /> <br /> <br /> <?php <br /> $width = $columns * 75; <br /> echo "<table width=".$width." border=1>"; <br /> $rw = 0; <br /> $cel = 1; <br /> while ($rw < $rows && $cel <= $cells) <br /> { <br /> echo "<tr>"; <br /> $cl = 0; <br /> while ($cl < $columns) <br /> { <br /> if ($cel <= $cells) <br /> { <br /> echo "<td><div align=center>".$cel."</div></td>"; <br /> $cel++; <br /> } <br /> $cl++; <br /> } <br /> echo "</tr>"; <br /> $rw++; <br /> } <br /> echo "</table>"; <br />?> <br /></div> <br /></body> <br /></em> <br />
0 komentar:
Posting Komentar