From the course: JavaScript: Enhancing the DOM
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Solution: Mini form validator
From the course: JavaScript: Enhancing the DOM
Solution: Mini form validator
(upbeat music) - [Instructor] And here's my solution. For example, I could paste in something here, but then it'll notice I did not specify an email address. Once I specify an email address, it's going to say that I need to have a certain password. So let's go ahead to specify 12341234, and say Register Again. And now it says it was successful. And here's the code I used to get it to do just that. So first of all, I selected all the elements from the page I needed, and I added the submit event. Then I prevent the page refresh with e.prefentDefault. Next, I'm going to check the name input value, the email, and the password inputs. Then if there is no problems found in any of the if statements, on line 30 and 31, I'm setting the content to "Registration successful!" And changing the style of the text color to green. As always, there's not one right answer. This is just one way you could have solved it.