Skip to content
Advertisement

How to get input form without reloading from HTML to flask?

I want to retrieve the input of the fields in the form of an array to the flask, on clicking a button, and without reloading the page. All the input fields are dynamic but the input filed id is static.

image

Here, above are the input fields and I want to retrieve the input with the click of the “calculate button”.

JavaScript

The above code is included jinja where it is adding fields dynamically from the below dictionary.

JavaScript

I am trying to achieve it using js, ajax. this is what I came up with, I don’t know much of it but I tried to understand and found the below and edited it.

// form id===> execution_form

JavaScript

Advertisement

Answer

You are taking the right approach. AJAX is the only way to transfer the form without having to reload the page.

According to the specification, the “for” attribute of the label relates to the ID of the input field, so this is also dynamic. In addition, in order to serialize the data, a “name” attribute is required for each input field.

To receive the data as an array, I recommend transmitting it as JSON.

JavaScript

The following is the route to receive the data.

JavaScript

I wish you success in implementing your project.

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