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.
Modify form values with vanilla JavaScript - JavaScript Tutorial
From the course: JavaScript: Ajax and Fetch
Modify form values with vanilla JavaScript
- [Instructor] My form has event listeners and I have references to the data that I need from the response. So, at this point, my finals step for the form is to actually put the nine-digit zip code data into the form. To add data to a form field, I can use the same value property of the element reference that I used to get the values from the other input elements. I have a reference to the zip code input element saved with the variable name zip field. So, down in my update UI success function, I can comment out my console.log statements, and I'm just going to take out both of them because I don't really need them anymore, and instead, I can specify zipfield.value equals and then I can just copy the same expression that I console.logged previously, zip and a hyphen and plus four. And so, in this case, I'm saying instead of getting the value from the zip field, I am specifying a new value, which is then placed in that form field. So I'm going to save my changes. I'm going to go live…
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
-
-
-
-
-