cainam29 Posted April 23, 2013 Share Posted April 23, 2013 I have a code that calls my retrieve and delete php, both are working properly I can retrieve and delete data from db. I am getting the alert confirming if I want to delete the data which is good as well. But whenever I click YES or NO I am getting the message: Record/s could not be deleted!, instead of Record/s has been deleted! at all even if the record was indeed deleted from the database. I am not posting my retrieve and delete php since they are both working. Just need to correct how the alert message would be displayed. Here's my script that query and delete from db: $(document).ready(function(){$("#RetrieveList").on('click',function() {var xid = $('#XiD').val();var date = $('#Date').val();$.post('resultgenerator_test.php',{xid:xid, date:date}, function(data){$("#results").html(data);});return false;});$("#DeletefromDB").click(function() {if (confirm("Are you sure you want to delete this Record/s?"))var id = $('input[name=checkbox]:checked').map(function(){return $(this).val();}).get();$.post('deletedata_test.php',{id:id}, function(data){$("#result").html(data);if(data == 'true') {$('#'+id).remove();alert('Record/s has been deleted!');}else {alert('Record/s could not be deleted!');}document.messages.submit();return false;}); });}); Quote Link to comment https://forums.phpfreaks.com/topic/277208-alert-message-after-delete-not-working-properly/ Share on other sites More sharing options...
Psycho Posted April 23, 2013 Share Posted April 23, 2013 (edited) First off, the code you have posted is JavaScript and you posted in the PHP forum. << Moving to JS forum >> But, here is the code to determine the message that is displayed: if(data == 'true') { $('#'+id).remove(); alert('Record/s has been deleted!'); } else { alert('Record/s could not be deleted!'); } You are checking if the variable 'data' is equal to the string value 'true'. I don't see where data is defined (looks like it is passed into the function). But, it is obvious that it is not equal to the string 'true'. Either you meant to be checking if 'data' is the Boolean true if(data == true) better yet . . . if(data) Or, data doesn't have the value you think it does. Edited April 23, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/277208-alert-message-after-delete-not-working-properly/#findComment-1426100 Share on other sites More sharing options...
cainam29 Posted April 23, 2013 Author Share Posted April 23, 2013 nice point...ill re-check my entire code...thanks... Quote Link to comment https://forums.phpfreaks.com/topic/277208-alert-message-after-delete-not-working-properly/#findComment-1426117 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.