Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[FLASK] checkbox onclick event
#1
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
Reply
#2
(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.
Reply
#3
(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 ?

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.


Thanks for the fast reply !
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Disable checkbox of google maps markers/labels using selenium erickkill 0 1,259 Nov-25-2021, 12:20 PM
Last Post: erickkill
  Parsing html page and working with checkbox (on a captcha) straannick 17 11,289 Feb-04-2021, 02:54 PM
Last Post: snippsat
  Using Python request without selenium on html form with javascript onclick submit but eraosa 0 3,171 Jan-09-2021, 06:08 PM
Last Post: eraosa
  Clicking on element not triggering event in Selenium Python (Event Key is not in data dkaeloredo 2 4,274 Feb-16-2020, 05:50 AM
Last Post: dkaeloredo
  [Flask] flask not submitting text entry when mixed with checkbox entries Prince_Bhatia 4 8,542 Oct-12-2018, 05:40 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020