
code:
<!DOCTYPE html>
<html>
<head>
<title>Percobaan</title>
</head>
<body id="kontol">
<form action="index.php" method="POST">
<input type="text" placeholder="Background" name="background">
<input type="submit" value="proses" name="proses">
</form>
<?php
$terima = strtolower($_POST['background']);
$warna = "grey";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if ($terima == "merah") {
$warna = "red";
} elseif ($terima == "kuning") {
$warna = "yellow";
} elseif ($terima == "hijau") {
$warna = "green";
} elseif ($terima == "ungu") {
$warna = "purple";
}
}
echo "<script type='text/javascript'>
document.getElementById('kontol').style.backgroundColor = '$warna';
</script>";
?>
</body>
</html>
code 2:
<!DOCTYPE html>
<html>
<head>
<title>percobaan bikin website</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body id="demo">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<table>
<tr>
<td>Background: </td>
<td><input placeholder="Background" type="text" name="bg"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="proses" name="proses"></td>
</tr>
</table>
</form>
<script type="text/javascript">
<?php print("document.getElementById('demo').style.backgroundColor = '".$_POST['bg']."'"); ?>
</script>
</body>
</html>
Komentar
Posting Komentar