I have a table whose rows are made draggable using sortable property as mentioned below.
<script type="text/javascript">
$(function () {
$("#tblLookup1 tbody").sortable({
items: 'tr',
cursor: 'pointer',
axis: 'y',
dropOnEmpty: false,
start: function (e, ui) {
ui.item.addClass("selected");
},
stop: function (e, ui) {
ui.item.removeClass("selected");
},
receive: function (e, ui) {
$(this).find("tbody").append(ui.item);
}
});
});
</script>
Now, once rows are dragged and dropped I have created an update button which is used to update the new order to database.
<input type="submit" class="btn CreateButtonColor" id="btnSave" value="Update"/>
Now I wish to have an alert, if the user drags and drops the rows and forgots to click on update, how to put warning so that user cannot navigate to other pages without saving?
warning something like below
if (confirm('Do you want to save the data before leaving?')) {
// Update code
}
else
{
// do nothing
}
where shall I place the above block of code?