How do i pass a variable from a html form to the main page?

What I’m trying to do:
i have a html form that includes a variable that is being changed based on activity on the website. the value is either 0 or 1 and i want to send it through uplink to my raspberry pi pico w. when the value is 1, a motor is activated by the gpio pin, when its 0, it is deactivated.

What I’ve tried and what’s not working:
i have seen that modules can store global variables that can be used everywhere else, but i dont know how to pass the value from the html form to the module.

Hi @marcelheadroom and welcome to the forum!

Could you provide some code to show what you’ve tried to do? this is the website

python code is in another reply

since i posted my question, i have changed the code a little. The website is supposed to check if the phone is being shaken. if it is shaken, the page turns green, if it isnt, it turns red. while it is shaken, the website should also send the value 1 to my raspberry pi pico w and while it isnt shaken, it should set the value to 0. The script for changing the color depending on the shake status works fine and the connection between pico and the website is also established since i had a test button on it to turn the LED on the pico on and off. In the “if” statement where i set the colors, i added a call function as you can see, because i thought since the color change works, calling to python should work aswell.

The color changes fine, but changing the status of shaking doesnt work. I hope there is a simple solution to that


Housekeeping - please post formatted code snippets rather than screen shots.


# paste code here


It looks like you’re missing the first argument to in your JavaScript function.

function myFunc() {$('.content'), 'my_method', 'world')
1 Like

thank you, this should be the solution, but what do i put there for “.content” and “world”?

If you’re using one of the builtin themes then. .content is probably what you want. It’s any dom selector nested within your html form that you’re trying to access.

If you look inside standard-page.html you’ll find a div with that class.

“world” is just an argument being passed to the function. You can pass arbitrarily many arguments. If you don’t need to pass any arguments then leave this blank. But it looks like you need to pass either 1 or 0.

You may want to re-read the docs and which covers this

i changed the two lines of code that call the python function but it still doesnt work. i added another test button which calls the same function with the value 1 and that works, so it must be something between the javascript and the python back end. maybe my problem is somewhere in the setup of the files. i am totally new to programming and anvil, i just want this one thing to work for my little project. i read through the docs again but i cant find the information that would help me.

heres a clone of my app, i would be very thankful if you could take a quick look. i am already thankful for your help so far, i hope we can get this working soon.

Here’s an updated clone

I set an id on the form so we can use this id for You weren’t using a standard template so .content wasn’t a valid selector for your form.

I also fixed the call signature for update_status.

I’d consider rewriting the JavaScript functions as python code using anvil.js. But that’s a personal preference.

1 Like

this made everything work. thank you so much