As an extra precaution we could have written this 'else if' condition as 'else if (this.error Mes.inner HTML ! As soon as the user types any text then we can return another function value based on what the user starts typing.
The last 'else' conditional is simply a catchall in case the other conditions don't pass for whatever reason.
In this tutorial I'll show how to display the error beside the name field rather than pop-up the error message using the alert function.
The error will display stating there is no name in the name field (I use a username field; however, the code can easily apply to a name field) in the error region when the user clicks on the submit button.
Validating web forms is a critical skill for any web developer, ensuring that the data that's submitted is complete, accurate, and nonmalicious before it's sent off to the server.