148 lines
3.5 KiB
HTML
148 lines
3.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Profile Editor</title>
|
|
<style>
|
|
body {
|
|
font-family: 'Times New Roman', Times, serif;
|
|
background-color: #f8f9fa;
|
|
margin: 40px;
|
|
}
|
|
h2 {
|
|
text-align: center;
|
|
}
|
|
form {
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 0 8px rgba(0,0,0,0.2);
|
|
width: 400px;
|
|
margin: auto;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-top: 10px;
|
|
font-weight: bold;
|
|
}
|
|
input {
|
|
width: 100%;
|
|
padding: 8px;
|
|
margin-top: 5px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 5px;
|
|
}
|
|
button {
|
|
margin-top: 15px;
|
|
padding: 8px 16px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
#tambah {
|
|
background-color: #007bff;
|
|
color: white;
|
|
}
|
|
#reset {
|
|
background-color: #6c757d;
|
|
color: white;
|
|
}
|
|
#daftar {
|
|
margin-top: 30px;
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 0 8px rgba(0,0,0,0.2);
|
|
width: 400px;
|
|
margin: 30px auto;
|
|
}
|
|
.profile-card {
|
|
border-bottom: 1px solid #ccc;
|
|
padding: 10px 0;
|
|
}
|
|
.hapus-btn {
|
|
background-color: #dc3545;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
padding: 5px 10px;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<h2>Profile Editor</h2>
|
|
|
|
<form id="profileForm">
|
|
<label>Nama:</label>
|
|
<input type="text" id="nama" placeholder="Masukkan nama" required>
|
|
|
|
<label>Tanggal Lahir:</label>
|
|
<input type="date" id="tgl" required>
|
|
|
|
<label>Kota:</label>
|
|
<input type="text" id="kota" placeholder="Masukkan kota" required>
|
|
|
|
<button type="button" id="tambah" onclick="tambahProfil()">Tambah Profile</button>
|
|
<button type="reset" id="reset">Reset Form</button>
|
|
</form>
|
|
|
|
<div id="daftar">
|
|
<h3>Daftar Profile</h3>
|
|
<div id="listProfile"></div>
|
|
</div>
|
|
|
|
<script>
|
|
let profiles = [];
|
|
|
|
function tambahProfil() {
|
|
const nama = document.getElementById("nama").value.trim();
|
|
const tgl = document.getElementById("tgl").value;
|
|
const kota = document.getElementById("kota").value.trim();
|
|
|
|
if (!nama || !tgl || !kota) {
|
|
alert("Semua data harus diisi!");
|
|
return;
|
|
}
|
|
|
|
// Hitung umur
|
|
const lahir = new Date(tgl);
|
|
const sekarang = new Date();
|
|
let umur = sekarang.getFullYear() - lahir.getFullYear();
|
|
const bulan = sekarang.getMonth() - lahir.getMonth();
|
|
if (bulan < 0 || (bulan === 0 && sekarang.getDate() < lahir.getDate())) {
|
|
umur--;
|
|
}
|
|
|
|
// Simpan ke array
|
|
profiles.push({ nama, tgl, kota, umur });
|
|
tampilkanProfile();
|
|
document.getElementById("profileForm").reset();
|
|
}
|
|
|
|
function tampilkanProfile() {
|
|
let output = "";
|
|
profiles.forEach((p, index) => {
|
|
output += `
|
|
<div class="profile-card">
|
|
<strong>${p.nama}</strong><br>
|
|
Umur: ${p.umur} tahun<br>
|
|
Tanggal Lahir: ${p.tgl}<br>
|
|
Kota: ${p.kota}<br>
|
|
<button class="hapus-btn" onclick="hapusProfile(${index})">Hapus</button>
|
|
</div>
|
|
`;
|
|
});
|
|
document.getElementById("listProfile").innerHTML = output;
|
|
}
|
|
|
|
function hapusProfile(i) {
|
|
profiles.splice(i, 1);
|
|
tampilkanProfile();
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html> |