0

When I click on delete link it directly deletes it. I am making Jquery UI dialog box to prompt Y/N. It should prompt Yes/No. If yes- deleted or No -Original State.

Here is My PHP Code for that:

echo "<td><a name='delete' href='product_listing_delete.php?id=" . $row['id'] . "' onclick='call()' >Delete</a></td><tr>";

Here is my javascript code for that:

<script>

        function call() {
            $('<div></div>').appendTo('body')
                    .html('<div><h6>Yes or No?</h6></div>')
                     .dialog({
                         modal: true, title: 'message', zIndex: 10000, autoOpen: true,
                         width: 'auto', resizable: false,
                         buttons: {
                             Yes: function () {
                                 doFunctionForYes();
                                 $(this).dialog("close");
                             },
                             No: function () {
                                 doFunctionForNo();
                                 $(this).dialog("close");
                             }
                         },
                         close: function (event, ui) {
                             $(this).remove();
                         }
                     });
        }

        function doFunctionForYes() {
            alert("Yes");
            $('#msg').show();
        }

        function doFunctionForNo() {
            alert("No");
            $('#msg').show();
        }

    </script>
2
  • What is the exact issue? Commented Aug 16, 2016 at 9:42
  • I have made a alertbox it should prompt yes or no, for further proceed. Instead it directly deletes it, without prompting Y/N. Commented Aug 16, 2016 at 9:45

1 Answer 1

1

You have to make some changes:

echo "<td><a name='delete' href='product_listing_delete.php?id=" . $row['id'] . "' onclick='call()' >Delete</a></td><tr>";

this will directly delete your record by without prompting any kind of alert because you are providing a direct URL to delete.

Make these changes:

echo "<td><a name='delete' class='delete' id='".$row['id']."'>Delete</a></td><tr>";

JS:

$('.delete').click(function(){
    if(confirm('Are you sure'))
    {
        var id = $(this).attr('id');
        // ajax call to delete the record on the behalf of id
    }
});
Sign up to request clarification or add additional context in comments.

Comments

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.