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

Modify form values with vanilla JavaScript - JavaScript Tutorial

From the course: JavaScript: Ajax and Fetch

Start my 1-month free trial

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…

Contents