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

Solution: Form validation

From the course: JavaScript: Web Form Programming

Start my 1-month free trial

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…

Contents