SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>  
  2.     const form = document.getElementById('person-create-form');
  3.     function getInputs(event) {
  4.         event.preventDefault();
  5.         const name = document.getElementById('name-input').value;
  6.         const email = document.getElementById('email-input').value;
  7.         const age = document.getElementById('age-input').value;
  8.         const splitEmail = email.split('');
  9.        
  10.         if (parseInt(age) < 18) {
  11.             window.alert('You are underage.')
  12.         }
  13.         if(!splitEmail.includes('@')) {
  14.             window.alert('Please enter a valid email address.')
  15.         }
  16.         if (parseInt(age) > 18 && splitEmail.includes('@')) {
  17.             console.log(name);
  18.             console.log(email);
  19.             console.log(age);
  20.             form.reset();
  21.             window.alert('Info submitted!');
  22.         }
  23.     }
  24.     form.addEventListener('submit', event => getInputs(event));
  25. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top