Run the application, go to the homepage and hit on the
Sign in button (without adding any information for the username); what will happen?
Anyone can sign into the app without even entering a username! We probably should not allow this!
Let's do some client-side input validation! Follow these steps:
- Create the following folder
- Create the file
index.vmand add the following line at the bottom before
indexs.vmand add an
idattribute to the input element for username text field:
- We will use the
validate.jsand add the following to it:
document and add/remove/manipulate HTML elements of the page.
- Finally, update
index.vmand add an event listener to the form element so that upon submission of the form, the
validateUsernamefunction is invoked and the form is submitted if and only if that function returned true:
Now run the application again, and try to sign in without providing a user name; you must get the following: