0% found this document useful (0 votes)
364 views5 pages

Men-Generate Matriks Sel Pada Tabel

This document contains code for generating a matrix of cells in an HTML table. The HTML code allows the user to specify the number of rows, columns, and total cells. It then checks that the total cells does not exceed the maximum allowed based on the rows and columns. The PHP code generates the table based on the user input for rows, columns, and total cells, populating each cell with a number from 1 to the total cells.

Uploaded by

Devita AnjiLia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
364 views5 pages

Men-Generate Matriks Sel Pada Tabel

This document contains code for generating a matrix of cells in an HTML table. The HTML code allows the user to specify the number of rows, columns, and total cells. It then checks that the total cells does not exceed the maximum allowed based on the rows and columns. The PHP code generates the table based on the user input for rows, columns, and total cells, populating each cell with a number from 1 to the total cells.

Uploaded by

Devita AnjiLia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Universitas negeri malang

Fakultas teknik

Jurusan teknik elektro

s1 pendidikan teknik informatika

Men-generate matriks
Sel pada tabel

maret 2011

Tampilan fungsi sederhana untuk mengenerate matriks sel pada table.


Berikut ini syntax yang digunakan dalam membuat program diatas.
Syntax HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Generate Table Secara Fleksibel</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
width:178px;
height:24px;
z-index:1;
left: 284px;
top: 189px;
}
.style1 {
color: red;
font-weight: bold;
}
-->
</style>
</head>
<body>
<form method="post" action="tugasPrak2.php">
<h3 align="center" class="style1">Generate Table Secara Fleksibel</h3>
<div align="center">
<table width="327" border="0" bgcolor="#FFFFFF">
<tr bgcolor="orange">
<td width="121" style="text-align:center">Rows</td>
<td width="196"><strong>= </strong>
<input name="JumlahRow" type="text" id="JumlahRow" onKeyUp="getmax();"
onfocus="this.select();"></td>
</tr>
<tr bgcolor="pink">
<td style="text-align:center"><label>Columns</label></td>
<td><strong>= </strong>
<input name="JumlahColum" type="text" id="JumlahColum" onKeyUp="getmax();"
onfocus="this.select();"></td>
</tr>
<tr bgcolor="blue">
<td style="text-align:center">Cell Total </td>
<td><strong>= </strong>
<input name="JumlahCell" type="text" id="JumlahCell" onKeyUp="getmax();"
onFocus="this.select();"></td>
</tr>
<tr bgcolor="green">
<td style="text-align:center">Max Cells </td>
<td><strong>= </strong>
<input name="maxcells" type="text" id="maxcells" disabled="disabled" style="text-
align:center"></td>
</tr>
</table>
</div>
<div id="apDiv1">
<input type="submit" name="Generate" value="G e n e r a t e"><input type="reset"
name="Reset" value="R e s e t">
</div>
</form>
</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>
</html>

Syntax PHP

<!DOCTYPE html>
<html lang="en"
<html>
<head>
<title>Hasil Generate Tabel</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"]; ?>
<?php echo $rows; ?> <em>rows,</em><br />
<?php echo $columns; ?> <em>columns,</em><br />
<strong>Membutuhkan</strong> <?php echo $cells; ?> <em>cells,</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>

You might also like