I have a group of div boxes containing records from the database.
I want to be able to drag and drop a div box and delete that specific record from the table.
So far I can successful do the drag and drop to make the div disappear but the record
delete is not working.
My goal is to get the value of “data-id1” which contains a code for the DB while Im dragging the DIV.
<div id="all_reminders" runat="server">
<div class="reminder_listitem" data-id1="DRW1L3" id="node1" draggable="true"
ondragstart="drag(event)"><b>DRW1L3</b> - Reminder1</div>
<div class="reminder_listitem" data-id1="DRW1L5" id="node2" draggable="true"
ondragstart="drag(event)"><b>DRW1L5</b> - Reminder2</div>
<div class="reminder_listitem" data-id1="DRW1L7" id="node3" draggable="true"
ondragstart="drag(event)"><b>DRW1L7</b> - Reminder3</div></div>
function drop(ev){
ev.preventDefault();
var data = ev.dataTransfer.getData("Text");
var el = document.getElementById(data);
el.parentNode.removeChild(el);
delete_reminder(lcode);
}
document.ondrag = function(event) {
lcode = $(this).attr("data-id1");
console.log(lcode); ********************** THIS is returning UNDEFINED
};
function delete_reminder(lcode){
$.ajax({
url:"reminder_delete.php",
method:"POST",
data:{lcode:lcode},
dataType:"text",
success:function(data){
get_current_reminders();
}
});
}