Advertisement
metalx1000

JavaScript Validate HTML Form

Oct 9th, 2023
1,569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.       function validate() {
  2.         let form = document.querySelector("form");
  3.         Array.from(form.elements).forEach((input) => {
  4.           if( input.value == "" ){
  5.             alert(`${input.name} needs to be entered.`);
  6.             return false;
  7.           }
  8.         });
  9.       }
  10.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement