From the course: JavaScript: Web Form Programming
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Form validation
From the course: JavaScript: Web Form Programming
Solution: Form validation
(upbeat music) - [Instructor] Okay. So, let's take a look at how I chose to solve this particular challenge. And remember that we needed to change the background color of the text area as the user got closer to the character limit. And we also needed to define a custom validation message when the user chose to upload a file that was too large, in this case, more than 500 bytes. So, let's start with the first challenge. My code uses an Event Handler function, named CheckTextField, which I assign when the window loads. It handles the Input event, which fires whenever the content of the control changes immediately. And if we look down in the CheckTextField function, we can see that I retrieve the element where the event came from, and then get the value of the maxlength attribute on the control. Then, I check to see how many characters are in the control. So, that gives me the current length of the text that's in the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Overview of form validation approaches2m 10s
-
(Locked)
Leveraging basic browser validation3m 21s
-
(Locked)
Implementing better browser validation6m 43s
-
(Locked)
Using CSS to enhance dynamic validation9m 47s
-
(Locked)
Filtering key input9m 57s
-
(Locked)
Using JavaScript for validation7m 3s
-
(Locked)
Challenge: Form validation2m 21s
-
(Locked)
Solution: Form validation3m 53s
-
(Locked)
-