function handleGetFormData() {
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const city = document.getElementById("city").value;
const zipCode = document.getElementById("zip-code").value;
const status = document.getElementById("status").checked;
return {
name,
email,
city,
zipCode,
status
};
}
function isNumber(str){
return !isNaN(str);
};
function checkboxIsChecked() {
return handleGetFormData().status;
}
function validateFormData(formData) {
return formData !== null && isNumber(formData.zipCode) && checkboxIsChecked();
}
function submit(event) {
const warning = document.getElementById('warning');
const formData = handleGetFormData();
if (!validateFormData(formData)) {
warning.innerHTML = "Periksa form anda sekali lagi";
console.log('Form validation failed');
} else {
warning.innerHTML = "";
}
}
document.getElementById('submit-form').addEventListener('click', (event) => {
event.preventDefault();
submit(event);
console.log('semua di eksekusi')
});
halo kak! untuk no 6-10 selalu salah , apakah ada yang perlu diperbaiki ya ?