Tolong bantu jawab kira-kira kenapa masih error ya di soalnya? padahal code sudah jalan ?
function handleGetFormData() {
const name = document.getElementById(‘name’).value;
const city = document.getElementById(‘city’).value;
const email = document.getElementById(‘email’).value;
const zipCode = document.getElementById(‘zip-code’).value;
const status = document.getElementById(‘status’).checked;
return {
name,
city,
email,
zipCode,
status
};
}
function isNumber(input) {
return !isNaN(input) && !isNaN(parseFloat(input));
}
function checkboxIsChecked() {
const statusCheckbox = document.getElementById(‘status’);
return statusCheckbox.checked;
}
function validateFormData(formData) {
return (
formData.name.trim() !== '' &&
formData.city.trim() !== '' &&
formData.email.trim() !== '' &&
isNumber(formData.zipCode) &&
checkboxIsChecked()
);
}
function submit(event) {
const formData = handleGetFormData();
const warningDiv = document.getElementById(‘warning’);
if (!validateFormData(formData)) {
warningDiv.textContent = "Periksa form anda sekali lagi.";
} else {
warningDiv.textContent = '';
}
event.preventDefault();
}
document.getElementById(‘my-form’).addEventListener(‘my-form’, function(event) {
submit(event);
});