I am trying to add a confirmation box when deleting a <div>
using a <form onsubmission=return confirm("Please confirm");">
like in this thread, but the action attached to my form gets executed before I can see the confirmation dialog box. The <div>
are generated dynamically, and the form basically deletes a csv row using Python/Flask to be read back with JQuery/Javascript after modifications. My code looks more or less like this.
First I have a base html:
<div class="container">
<div id="projects"></div>
</div>
And then I use javascript to append multiple <div>
dynamically using information read from a csv through a Python/Flask server:
var ProjName = {{ ProjName|safe }};
$(document).ready(function(){
for(i = 0; i < {{ row_count|safe }}; i++) {
$('#projects').append('<div class="projectDivs" id="'+ i +'"><form onsubmit="return confirm("Do you really want to submit the form?");" action="/dashboard" method="post"><input type="hidden" name="hidden-value" value="'+i+'"><button value="delete" name="submit" class="close">×</button></form><center><h2>'+ ProjName[i] + '</h2></center></div>');
}
});
In the background, I am using Python/Flask to read, manipulate and serve the info, but I assume my problem is on the client side so no point showing that. The problem I have is when I press the 'x' to delete, the div gets deleted before the dialog box is shown... any help would be greatly welcomed.