2

page:content display.php

<td width="100"><a onclick="return confirmSubmit()" href="delete.php?id=<?php echo $row['id']; ?>&table=labour_details&return=content_display.php"><img src="../images/delete.png" border="0" alt="delete"></a></td>

page:delete.php

if(isset($_GET['id']) && isset($_GET['table']))
    {
        $id=$_GET['id'];
        $tablename=$_GET['table'];
        $return=$_GET['return'];




        if($tablename=="labour_details")
        {
                    $sql=mysql_query("SELECT * FROM `labour_details` WHERE `id`='$id'");
                    $row_1=mysql_fetch_array($sql);
                    $labour_name= $row_1['labour_name'];

                    if($labour_name!="")
                    {
                        $str=mysql_query("DELETE FROM `labour_details` WHERE `id`='$id'");
                        if($str)
                        {
                            header("location:$return?msg=Record Deleted Successfully!&id=$id");
                        }else{
                            echo "Problem in deleting :";
                        }
                    }

        }

}

my problem is where to add alert so that before deleting record it show javascript massage if allow then it will delete record.

function confirmSubmit()
{
    var agree=confirm("Are you sure you wish to Delete this Entry?");
    if (agree)
        return true ;
    else
        return false ;
}
7
  • Just add a prompt in the confirmSubmit ? Commented May 10, 2013 at 9:58
  • I suggest you read about AJAX, mysqli and PDO. Commented May 10, 2013 at 9:58
  • In confirmSubmit() function ? Commented May 10, 2013 at 9:58
  • in confirmSubmit() if confirmSubmit() returns true then link href is followed if not it stays on the same page. Commented May 10, 2013 at 9:58
  • it should work as is: if the user doesn't confirm confirmSubmit(), the link is not followed and the delete.php link is not followed Commented May 10, 2013 at 9:59

5 Answers 5

3

This line will show confirm dialogbox before redirect.

<a onclick="return confirm('Are You sure?')">...</a>
Sign up to request clarification or add additional context in comments.

Comments

1

First you need to create the confirmSubmit() function

<script>
function confirmSubmit()
{
    if (confirm('Are you sure you want to delete this?'))
    {
        return true;
    }
    return false;
}
</script>

Then you attach that to your A tag, as you have done..

<a href="..." onclick="return confirmSubmit();">blah</a>

1 Comment

and there is no need to conditional statement just return confirm('Are you sure you want to delete this?') in function body :P
1

You're probably looking for confirm.

Then, the body of the confirmSubmit function would look something like:

function confirmSubmit() {
    return confirm ("Are you sure you want to do this?");    
}

This works due to how event handlers work in javascript. Confirm returns true when the user clicks OK and false when they click Cancel.

By returning a true/false value from an event handler function you tell the window whether to keep processing that event. Returning false (which happens when the user clicks Cancel) tells the browser to stop processing the event and not follow the link.

Comments

0
<td width="100"><a onclick="confirmSubmit(id)"><img src="../images/delete.png" border="0" alt="delete"></a></td>




function confirmSubmit(delete_id)
{
var r=confirm("Are you sure you want to delete?");

if(r==true)
{
         window.location.href = "delete.php?id="+delete_id"; ?>&table=labour_details&return=content_display.php"
    }
}

1 Comment

with my function you will surely get an alert box to confirm delete or not....... check it and try it out.....
0
<a onclick="return confirm('Are you sure?')" href="delete.php">delete</a>

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.