Selamat malam kak. Saya izin bertanya karena selama berhari-hari yg nomer 10 masih mengalami error. Berikut ini kodingan lengkap milik saya:
-
Fungsi handleGetFormData()
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;let data = { name: name, city: city, email: email, zipCode: zipCode, status: status }; return data;
}
-
Fungsi isNumber(str)
function isNumber(str) {
if (isNaN(str))
{
return false;
}
else {
return true;
}
} -
Fungsi checkboxIsChecked()
function checkboxIsChecked() {const checkbox = document.getElementById('status'); if(checkbox.checked){ return true; } else{ return false; }
}
-
Fungsi validateFormData()
function validateFormData(formData) {if(isNumber(formData.zipCode) && checkboxIsChecked() && formData){ return true; } else { return false; }
}
-
Fungsi submit()
function submit() {
const warning = document.getElementById(‘warning’);
const formData = handleGetFormData();if(validateFormData(formData) == false) { return warning.textContent = 'Periksa form anda sekali lagi'; } else { return warning.remove(); }
}
-
Memanggil fungsi submit()
document.getElementById(‘submit-form’).addEventListener(‘click’,(event)=> {
event.preventDefault();
submit();
})
Mohon bantuannya kak. Terima kasih