When I finished this task, I submitted a username and a password and I received an answer from the form that said " Hurray for client-side validation!". However, I do not see the code that creates this answer in the html file. Where is this code written?
normally the form is send to the back-end (server), where its processed. In this case, that is prevented and JS handles the form (see login.js), there should be a directory/folder icon somewhere which shows you all the files in this exercise
You are right! I found the directory and there are 4 files (2 html, 1 CSS and 1 JS called login.js).
You have been of great help. Now I understand a bit more what happens in this code.
I havenât really done much, you went through the code and improved your own understanding. Nice job
If you type âcodecademyâ into the Username field and âilovecodingâ into the Password field you will receive the message, âWe love coding too!â.
I discovered this after looking at the js file.
thanks so much for this⌠but also how can one make this else if statement to occur on the browser? have been trying to understand it
one of the fields needs to be false (which is then flipped to true (with not operator (!
))
so leaving one or both fields empty should do the tricky
OK. THANKS
But remember the field was made to be mandatory⌠so when I left any empty I was asked fill it inâŚ
my question is âhow do i get the âadd some client-side validationâ message to appear?â
I havenât done the exercise, and I couldnât find the exercise url anywhere, do you have it for me?
if you have html5 required
attribute, I donât think you can get the else if
but that is the point? The message says add some client validation for a reason. This message is there to inform you forgot to add validation
I think I covered it? the else if
clause is there to inform you that you forgot to add validation to your form.
getting the else if clause to be executed would be a bad thing
okâŚso the html code needs to be corrected so the âelse ifâ message can show?
exactly
Maybe this lesson doesnât use the greatest example, but using exceptions/condition to prevent an unwanted outcome (or display a message) is good practice
thank you so much for your contribution
Remove the html attributes minlength
and required
then if you submit the form with either username/password as a falsey, it will show the statement within the else if
block. The else if
statement is uneccesary if there is a minlength
and a required
attribute within the html <input/>