Skip to content
Advertisement

Form does not have data in FormData javascript

I’m trying to submit a form without redirecting using AJAX. From the answers I saw the [best](new URLSearchParams(new FormData(form).entries()); ) I found (I think) without using jQuery was:

JavaScript

I’m trying to apply this mechanism in my code, but for some reason my form does not have information. I guess I’m calling the function before it gets recorded? But I’m not sure how to fix it.

My code (simplified):

HTML (using React and Reactstrap):

JavaScript

JS (inside the same React class):

JavaScript

Any help would be appreciated.

Advertisement

Answer

From MDN docs

Note: FormData will only use input fields that use the name attribute.

Try naming the input element:

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