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
user13315994
1591 silver badge7 bronze badges
1 Answer 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
Andrea Pollini
2904 silver badges8 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
type="hidden") form field with the variable's value.