smago

catur wahyu nugroho

catur wahyu nugroho

Nov 19, 2024

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Input</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="form-container">
<h1>Form Input</h1>
<form id="nameForm">
<label for="name">Masukkan Nama:</label>
<input type="text" id="name" name="name" placeholder="Masukkan nama Anda" required>
<button type="button" onclick="submitForm()">Submit</button>
</form>
<div class="output" id="output"></div>
</div>
<script src="scripts.js"></script>
</body>
</html>

styles.css

body {
font-family: Arial, sans-serif;
margin: 20px;
}
.form-container {
max-width: 400px;
margin: auto;
}
input {
display: block;
margin-bottom: 10px;
padding: 8px;
width: 100%;
box-sizing: border-box;
}
button {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.output {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
}

scripts.js

function submitForm() {
// Ambil nilai input
const name = document.getElementById("name").value;
// Tampilkan hasil di div output
const outputDiv = document.getElementById("output");
if (name) {
outputDiv.textContent = `Halo, ${name}!`;
} else {
outputDiv.textContent = "Silakan masukkan nama terlebih dahulu.";
}
}