user13315994
user13315994

Reputation: 149

Sending a javascript variable to python using forms

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?

Upvotes: 2

Views: 110

Answers (1)

Andrea Pollini
Andrea Pollini

Reputation: 290

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)

Upvotes: 1

Related Questions