Advertisement
Guest User

WrapperGoneWrong

a guest
Oct 26th, 2021
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             const $ = function(id) { return document.getElementById(id); }; //shorthand
  2.            
  3.             const show = function(id){ $(id).style.display = 'block'; }
  4.             const hide = function(id){ $(id).style.display = 'none'; }
  5.            
  6.             const $$ = function(inputElement, errorElement){ //if-ladder as discussed wrapped in function
  7.                 if($(inputElement).value == ''){
  8.                     show(errorElement);
  9.                     return false; //earlier: once fired, only one error is able to be raised in this method.
  10.                     //edit: now all elements fire and this return is not 'inherited' by myFunction output.
  11.                 }
  12.                 else{
  13.                     hide(errorElement); // error is hidden if value has been added
  14.                 }
  15.             }
  16.  
  17.             const myFunction = function(){ // all form fields are read and error messages are displayed if null input
  18.                 $$("firstName", "noFirstName"); //when empty field, should return false
  19.                 $$("lastName", "noLastName");
  20.                 $$("dob", "noDob");
  21.                 $$("address", "noAddress");
  22.                 $$("email", "noEmail");
  23.                 $$("psw", "noPsw")
  24.  
  25.                 // earlier: automatically returns true if conditions avoided
  26.                 // edit: onsubmit is reloading the page which is undesirable
  27.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement