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 problems 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?
  3. 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

Thank you

HTML

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

JS

$(function(){
    $("#delete").click(function() {
        // what should be add here? 
    });
});

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'

Sorry, I mess up the previous question as i found that the plugin i used in last question does not work for me.

1

2 Answers 2

1

i had done this by giving the id to the HTML element itself with data (HTML5 ref) sweet to use with jQuery. After this you can do an ajax call optional to delete server-side in the database.

Example

<a data-id="<?php echo $set[ListID]; ?>" class="delete-trigger" href='javascript:;'>Delete</a>

JS

$(function(){
    $("#delete-trigger").click(function() {
        var id = $(this).data('id');
        $.ajax({
            url: 'http://yoururl.com/delete.php?id=' + id,
            success: function(data) {
                console.log('deleted');
            }
        });
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

This ask the user whether to delete the list?
no this is just the execution of deleting a "list". to ask the user for confirm just do: var booleanOfAnswer = confirm('your question'); - help for this, here
1

html

<a class="delete" data-listname="<?php echo $set['ListName']?>" href="delete.php?id=<?php echo $set['ListID']?>">Delete</a>

js

$(function(){
  $(".delete").click(function() {

    return confirm('Are you sure you want to delete ' + $(this).data('listname') + '?');

 });
});

3 Comments

Won't this refresh the page, not allowing the js to be run? Also, shouldn't # be .
Sorry but I found that there is a flaw, if there are more than one link, one of them will not popup but directly go to the delete.php
Sorry, my mistake. Need to replace an ID selector with CLASS selector. I changed my answer

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.