2

Suppose I have created a form

<form action=" " method="POST">
<input type="text" name="xyz">
<input type="text" name="abc">
<button type="submit" >submit</button>
</form>

Using this I can access the values with the name "xyz" and "abc"

if request.method == "POST":
 val1 = request.form['abc']
 val2 = request.form['xyz']

But I also want to access a javascript variable using the same form. Since javascript variable has no identifier as like <input> has 'name', So is there any way to do so?

asked Jun 30, 2020 at 20:56
1
  • Use javascript to populate a hidden (type="hidden") form field with the variable's value. Commented Jun 30, 2020 at 21:00

1 Answer 1

1

If you want to pass a JavaScript variable to python using the form you can add an input field of type hidden with the value of the is variable (you can set it from JavaScript using document.getElementBy... functions)

answered Jun 30, 2020 at 21:01
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.