Simple Form Validation in Javascript


Check if a form input is empty before submitting.

Source Code

function validateForm() {
  let value = document.getElementById('myInput').value;
  if (value === "") {
    alert("Name must be filled out");
    return false;
  }
  return true;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments