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

Request data in response to an event - JavaScript Tutorial

From the course: JavaScript: Ajax and Fetch

Start my 1-month free trial

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…

Contents