Skip to content
Advertisement

Use [e.target.name]=e.target.value inside object

I have this object:

JavaScript

and i need to fill it in a form.

i use this function:

JavaScript

and this inside the form:

JavaScript

The form works onsubmit, and create values in the object with the property name, and the value.

But if the property (p.e: ‘title_image_lateral’), not put the new value in the correct place in the object, instead create a new element in the root of the object: title_image_lateral: (value submited in the form).

I thik that i can change the ‘root’ for the itemData[i][e.target.name]=e.target.value; , but i can not achieve.

Maybe i can create state for this values, and then onsubmit the form, set in the object…but maybe is made a big surround.

Some light for my issue.

Thanks.

Here the entire file:

JavaScript

Advertisement

Answer

Check if this suits your needs:

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