From the course: JavaScript: Ajax and Fetch
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Request data in response to an event - JavaScript Tutorial
From the course: JavaScript: Ajax and Fetch
Request data in response to an event
- [Instructor] Where DOM manipulation really shines is when your code changes the view in response to an event whether that's a user event or a browser event. My plan for this form is to respond to a user leaving either the address, city or state field. Leaving a field triggers the blur event and when a user leaves one of those fields, my code is going to check if all three of them have content. And if they do, then I want to fire off a request to SmartyStreets, sending those three pieces of info and getting back data on that address including the nine-digit zip code. So the first thing I'm going to do is to define a function called checkCompletion that I'll call each time a user leaves one of those fields. So down here underneath the createRequest function, I'm going to say const checkCompletion. I can check the value of a form field using the value property of the referenced element. So I'm going to check if addressField.value and I want to see if that is anything other than empty…
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
-
-
-
-
What is the DOM?3m 19s
-
(Locked)
Select elements with vanilla JavaScript3m 43s
-
(Locked)
Request data in response to an event4m 14s
-
(Locked)
Add an event listener2m 12s
-
(Locked)
Work with JSON data6m 52s
-
(Locked)
Modify form values with vanilla JavaScript4m 58s
-
(Locked)
Modify element content with vanilla JavaScript5m 49s
-
(Locked)
Challenge: Modify the DOM58s
-
(Locked)
Solution: Modify the DOM7m 55s
-
-
-
-
-