[FLASK] checkbox onclick event - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: [FLASK] checkbox onclick event (/thread-26750.html) |
[FLASK] checkbox onclick event - Mad0ck - May-12-2020 Hello, Im new to this forum, and already asking my first question .... I googled a lot, but didnt found a clear answer for that. Is it (somehow) possbile to add a "onclick" event to a checkbox / slider in flask ? Just like in javascript ? The goal should be that i check/uncheck a checkbox on the website, and my databaseUpdate function gets called, without pressing a confirm button, or a refresh of the site. ( in my opinion a confirmation button is intolerable for a user. It simply sucks to " confirm " a slider change / checkbox state change, to say it in rough words ... ) Well, back to the problem. How could I solve that ? Does it make sense, to set a href (/ does a onclick work ? )attribute to my checkbox, which redirects to a route, where i just call the update db function ? I dont really know ... Would appreciate any kind of help ! Thanks RE: [FLASK] checkbox onclick event - scidam - May-13-2020 (May-12-2020, 09:51 AM)Mad0ck Wrote: Does it make sense, to set a href (/ does a onclick work ? )attribute to my checkbox, which redirects to a route, where i just call the update db function ? This is almost right way to solve the problem. Roughly speaking, the algorithm should be the following: 1. You need to implement a function (in javascript) that will be called when the checkbox is clicked. 2. This function will initiate a request (e.g. XMLHttpRequest) to a specific route; 3. On the backend tail, you need to implement a view that will process such requests (using Python, Flask); To make all of this more secure, you probably will need to use flask-related features, such as sessions and csrf-token handling. RE: [FLASK] checkbox onclick event - Mad0ck - May-14-2020 (May-13-2020, 12:32 AM)scidam Wrote:(May-12-2020, 09:51 AM)Mad0ck Wrote: Does it make sense, to set a href (/ does a onclick work ? )attribute to my checkbox, which redirects to a route, where i just call the update db function ? Thanks for the fast reply ! |