legit_hacker_2000
legit_hacker_2000

Reputation: 53

Sending extra data with Flask form?

I'm new to web development so apologies if this is an obvious question.

My website has a timer as below

enter image description here

The radio buttons at the bottom are a flask form and I can easily access the value of that on the backend.

The timer is build in HTML/JS and the time is represented with a <span> tag, that's innerHTML is repeated updated by the Javascript function.

How do I send this value back to the endpoint along with the value of the radio button? I know I could make an ajax request to the endpoint with the final timer value but then the Flask form will be useless. Is there some way to attach the innerHTML value to the form?

I tried creating a form element, setting the label to 00:00:00 then updating this from the JavaScript, then when the form is sent back accessing the label value, but no matter what it's updated to the Flask backend shows it as 00:00:00

Upvotes: 3

Views: 644

Answers (1)

Karl Sutt
Karl Sutt

Reputation: 575

Setting and updating a label won't send the label "value" when the form is submitted. Instead, you could add a hidden field in your Flask form. Then, the same JavaScript function that updates the <span> for the timer could update the value of the hidden field at the same time. When the form gets submitted, the value of the hidden field will get sent along with the value for the radio buttons.

Upvotes: 4

Related Questions