Skip to content
Advertisement

How do you retrieve selected options BEFORE the user have submitted the form?

I’m trying to get data which is selected inside of a multiselect. However, I want to display the selected options inside another field in the form. Therefor I don’t want to send the actual form before getting the data and displaying it.

I want to use the value mainly to gather information from a database which gives the user a amount specified for that select option!

I have tried multiple different solutions from different threads but unfortunately they haven’t worked!

Select which i want to gather the selected options from:

JavaScript

Input field I want to display the data in:

JavaScript

Code:

JavaScript

Advertisement

Answer

To update the value of an input, assign to its value property, not the attribute.

You should use the join() method to convert the array to a string with a specified delimiter.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement