Skip to content
Advertisement

How do I get my HTML button to delete the right list item from a SQLite database?

I’m a beginner, so forgive any stupidity in advance. I’m using Flask (and by extension Jinja2) to create a simple web app — one that basically lets you type a movie into a web form, which adds it to a SQLite database. I’ve gotten Flask to very nicely iterate through all the movies in the database and print them to the page upon load.

I want to include a “Delete” button next to each movie. Getting the button to appear is simple. But I’m not sure how to tie the button back to the function delete_movie() such that it will delete the correct movie associated with the button pressed.

Since there will be a button next to each movie, the form element must be dynamically named, I’m guessing. But if it’s dynamically named, how do I pass the correct value back to the function? This is what I’ve got so far:

JavaScript

Thanks in advance for any help!

Advertisement

Answer

Just add a hidden input to every form with the element id/name that you want to delete as the value :)

eg.

JavaScript
Advertisement