Membuat Form Registrasi
Membuat Form Registrasi
Identitas Diri
Nama: Muhammad Rifqi Ma'rufNRP: 5025221060Kelas: Pemrograman Web ATahun: 2023
Deskripsi Tugas
Source Code
*HTML*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Form Registrasi Mahasiswa</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<form id="registrationForm">
<label for="nama">Nama Mahasiswa<span class="required">*</span>:</label>
<input
type="text"
id="nama"
name="nama"
oninput="suggestCourse()"
required
placeholder="Masukkan nama"
/>
<label for="nim">NIM<span class="required">*</span>:</label>
<input
type="text"
id="nim"
name="nim"
required
placeholder="Masukkan NIM"
/>
<label for="mataKuliah"
>Mata Kuliah<span class="required">*</span>:</label
>
<input
type="text"
id="mataKuliah"
name="mataKuliah"
required
placeholder="Masukkan mata kuliah"
/>
<label for="dosen">Dosen<span class="required">*</span>:</label>
<input
type="text"
id="dosen"
name="dosen"
required
placeholder="Masukkan nama dosen"
/>
<button type="submit">Submit</button>
</form>
<div id="suggestions"></div>
<script src="script.js"></script>
</body>
</html>
*CSS*
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
form {
max-width: 1000px;
margin: auto;
text-align: left;
}
label,
input {
display: block;
margin-bottom: 10px;
}
button {
padding: 10px 20px;
}
#suggestions {
margin-top: 20px;
}
*JS*
function suggestCourse() {
const input = document.getElementById("nama").value.toLowerCase();
const suggestionsDiv = document.getElementById("suggestions");
suggestionsDiv.innerHTML = "";
if (input.includes("john")) {
suggestionsDiv.innerHTML = "Rekomendasi: Matematika Dasar";
} else if (input.includes("jane")) {
suggestionsDiv.innerHTML = "Rekomendasi: Bahasa Inggris";
}
}
document
.getElementById("registrationForm")
.addEventListener("submit", function (event) {
event.preventDefault();
const nama = document.getElementById("nama").value;
const nim = document.getElementById("nim").value;
const mataKuliah = document.getElementById("mataKuliah").value;
const dosen = document.getElementById("dosen").value;
if (nama === "" || nim === "" || mataKuliah === "" || dosen === "") {
alert("Mohon isi semua form.");
return;
}
});
Komentar
Posting Komentar