Custom button event

What I’m trying to do:
i’m a html beginner, trying to add a new event to my customized button but in my html file when i declare the onclick=‘function’ it does not goes to the python func i

Code Sample:
html:
submit

the python code inside a class who using the html file
python:
def onButtonClick(self):
do something…
how can i customize my on click func using the python class?

Javascript cannot call python functions directly. You can use the anvil.call function from javascript but I will suggest using the anvil.js module for this

Here is how you can do it:

from anvil.js.window import document

document.getElementById('YourBTN').onclick=self.onButtonClick

Of course you can use ClassName, TagName, Query Selector, jQuery etc. to get your dom

2 Likes