Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const $ = function(id) { return document.getElementById(id); }; //shorthand
- const show = function(id){ $(id).style.display = 'block'; }
- const hide = function(id){ $(id).style.display = 'none'; }
- const $$ = function(inputElement, errorElement){ //if-ladder as discussed wrapped in function
- if($(inputElement).value == ''){
- show(errorElement);
- return false; //earlier: once fired, only one error is able to be raised in this method.
- //edit: now all elements fire and this return is not 'inherited' by myFunction output.
- }
- else{
- hide(errorElement); // error is hidden if value has been added
- }
- }
- const myFunction = function(){ // all form fields are read and error messages are displayed if null input
- $$("firstName", "noFirstName"); //when empty field, should return false
- $$("lastName", "noLastName");
- $$("dob", "noDob");
- $$("address", "noAddress");
- $$("email", "noEmail");
- $$("psw", "noPsw")
- // earlier: automatically returns true if conditions avoided
- // edit: onsubmit is reloading the page which is undesirable
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement