Skip to content
Advertisement

Auto populate a field based on the value of the other field [closed]

I need a JavaScript that will let me auto-populate a text field based on another field which is a select list type.

Here is my HTML markup:

JavaScript

The former field’s value will be automatically entered as the latter field’s value. That’s what I want to do here.

Advertisement

Answer

You have to add an event listener to your select field and populate its value to your text field. Your HTML is a little messy.. so I will just write the jquery in general. You can fiddle around with it.

you have to set this event listener as soon as the body is loaded. So on your HTML

JavaScript

and on your javascript

JavaScript

Hope this helps.

Advertisement