| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 141bd01 commit 6c9cd03
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,37 +88,41 @@ | |||
| 88 | 88 | // is valid, we remove the error message. | |
| 89 | 89 | emailError.innerHTML = ''; // Reset the content of the message | |
| 90 | 90 | emailError.className = 'error'; // Reset the visual state of the message | |
| 91 | + } else { | ||
| 92 | + // If there is still an error, show the correct error | ||
| 93 | + showError(); | ||
| 91 | 94 | } | |
| 92 | 95 | }); | |
| 93 | 96 | ||
| 94 | 97 | form.addEventListener('submit', function (event) { | |
| 95 | - // Each time the user tries to send the data, we check | ||
| 96 | - // if the email field is valid. If it is, we let the form submit | ||
| 98 | + // if the email field is valid, we let the form submit | ||
| 97 | 99 | ||
| 98 | - // If it isn't, we start the process of working out why it isn't | ||
| 99 | - // and display an appropriate error message | ||
| 100 | 100 | if(!email.validity.valid) { | |
| 101 | - if(email.validity.valueMissing) { | ||
| 102 | - // If the field is empty | ||
| 103 | - // display the following error message. | ||
| 104 | - emailError.textContent = 'You need to enter an e-mail address.'; | ||
| 105 | - } else if(email.validity.typeMismatch) { | ||
| 106 | - // If the field doesn't contain an email address | ||
| 107 | - // display the following error message. | ||
| 108 | - emailError.textContent = 'Entered value needs to be an e-mail address.'; | ||
| 109 | - } else if(email.validity.tooShort) { | ||
| 110 | - // If the field doesn't contain an email address | ||
| 111 | - // display the following error message. | ||
| 112 | - emailError.textContent = `Email should be at least ${ email.minL ength } characters; you entered ${ email.value.length }.`; | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - // Update the styling appropriately | ||
| 116 | - emailError.className = 'error active'; | ||
| 117 | - | ||
| 118 | - // Finally we prevent the form from being sent by canceling the event | ||
| 101 | + // If it isn't, we display an appropriate error message | ||
| 102 | + showError(); | ||
| 103 | + // Then we prevent the form from being sent by canceling the event | ||
| 119 | 104 | event.preventDefault(); | |
| 120 | 105 | } | |
| 121 | 106 | }); | |
| 107 | + | ||
| 108 | + function showError() { | ||
| 109 | + if(email.validity.valueMissing) { | ||
| 110 | + // If the field is empty | ||
| 111 | + // display the following error message. | ||
| 112 | + emailError.textContent = 'You need to enter an e-mail address.'; | ||
| 113 | + } else if(email.validity.typeMismatch) { | ||
| 114 | + // If the field doesn't contain an email address | ||
| 115 | + // display the following error message. | ||
| 116 | + emailError.textContent = 'Entered value needs to be an e-mail address.'; | ||
| 117 | + } else if(email.validity.tooShort) { | ||
| 118 | + // If the data is too short | ||
| 119 | + // display the following error message. | ||
| 120 | + emailError.textContent = `Email should be at least ${ email.minLength } characters; you entered ${ email.value.length }.`; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + // Set the styling appropriately | ||
| 124 | + emailError.className = 'error active'; | ||
| 125 | + } | ||
| 122 | 126 | </script> | |
| 123 | 127 | </body> | |
| 124 | 128 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments