1

Here is the extract code of how to make a confim box when delete,

For html part: A link is to trigger JS code , but it will trigger the php code at same time

For JS part: popupbox is triggered

For php part: Process the sql query, it should be ok

The problem are:

  1. I should use js to trigger the php page?But how can i let the php page know that which ListID i want to delete?

  2. What should i put in the html link?

Thank you

html

<a id="delete" href='delete.php?id=$set[ListID]'>Delete</a>

Js

$(function(){
  $("#delete").click(function() {
    $.messager.alert('Warning','The warning message');  
    $.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){  
        if (r){  
            alert('ok');  
        }  
    });  
 });
});

php

//connection db
INSERT  INTO delete_list SELECT * FROM list WHERE ListID=?;    
INSERT  INTO delete_user_list SELECT * FROM user_list WHERE ListID=?;    
INSERT  INTO delete_require_attributes SELECT * FROM require_attributes WHERE ListID='2';    
INSERT  INTO delete_subscriber SELECT * FROM subscriber WHERE ListID=?;    
INSERT  INTO delete_subscriber SELECT * FROM subscriber WHERE ListID=?;    
DELETE FROM list WHERE ListID = '1'

What if i want to include the list name in the popup box e.g. do you want to delete list A ,where list A is a variable already. The only thing is how can i append it to the popup box

"<tr><td>".$set['ListName']."</td><td>"

5 Answers 5

1

I don't know what $.messager does, but I suppose this should work

$(function(){
  $("#delete").click(function(evt) {
    evt.preventDefault();
    var urlscript = this.href;  /* read link url (e.g. delete.php?id=314159) */

    $.messager.alert('Warning','The warning message');  
    $.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){  
        if (r) {                  
           $.ajax(urlscript); /* make ajax call to that url with the right id */    
        }  
    });  
 });
});

and I supposing that your source code is actually showing smthg like

<a id="delete" href='delete.php?id=314159'>Delete</a>

so on the ajax call you're sending that id.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you , since the php code is delete based on a ID e.g. delete.php?id=$set[ListID] , how can i post it to the php if i am using js? Thanks
0

Try this:

if (confirm("Question?")) {
     // IF OK CLICKED
     $.get('delete.php?id=MyID', function(data) {
         alert('List DELETED');
    });
}

1 Comment

What if i want to include the list name in the popup box e.g. do you want to delete list A ,where list A is a variable already.
0
$("#delete").click(function(e) {
    e.preventDefault();
    var url = this.href;
    $.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){  
        if (r){  
            location.href = url;
        }  
    });

Comments

0

Let the link trigger the javascript code to show the popup window for delete confirmation. at the same time, you can update value of a hidden field in your page with the selected item id. When you user confirms the deleting by clicking on the "Yes" button in the confirm box. Read the value of the hidden input and then post that to the server (php) page to do the actual deletion from the database.

Comments

0

I wouldnt send the ID as a GET, else people can increment the value and delete your records?

<a class="delete" id="someId" >Delete</a>

$('.delete').click(function() {
  var id = $(this).attr('id');

  $.messager.alert('Warning','The warning message');  
  $.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){  

   if (r) {       
      $.post('delete.php', {id:id}, function(response) {
         //check the status of the reponse
      });  
   });
});

1 Comment

Sorry but a link is not pressable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.