2013-05-10 71 views
2

页:内容Display.php的PHP代码之前,JavaScript警告

<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> 

页: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 :"; 
         } 
        } 

     } 

} 

我的问题是在哪里添加警报,以便在删除记录之前,它显示的javascript按摩,如果允许那么它会删除记录。

function confirmSubmit() 
{ 
    var agree=confirm("Are you sure you wish to Delete this Entry?"); 
    if (agree) 
     return true ; 
    else 
     return false ; 
} 
+0

只需在confirmSubmit中添加提示? – JNDPNT 2013-05-10 09:58:23

+0

我建议你阅读关于AJAX,mysqli和PDO。 – elclanrs 2013-05-10 09:58:33

+0

在'confirmSubmit()'函数中?如果confirmSubmit()返回true,则在confirmSubmit()中返回 – Rikesh 2013-05-10 09:58:46

回答

3

此行将在重定向之前显示确认对话框。

<a onclick="return confirm('Are You sure?')">...</a> 
+0

首先我已经downvoted,但现在它是很好的解决方案:) – Robert 2013-05-10 10:04:17

1

首先,你需要创建的confirmSubmit()函数

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

然后你附上你的标签,因为你做了..

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

它将无法正常工作更改onclick“return confirmSubmit()” – Robert 2013-05-10 10:02:23

+0

啊好啊发现! – Dale 2013-05-10 10:02:40

+0

并且不需要条件语句只需返回confirm('您确定要删除此?')在函数体中:P – Robert 2013-05-10 10:03:36

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" 
    } 
} 
+0

没有意义:) return confirm(“Question”);这就是全部:P – Robert 2013-05-10 10:02:56

+0

看到..... !! – 2013-05-10 10:10:01

+0

与我的功能,你一定会得到一个警告框,以确认删除或不.......检查它并尝试一下..... – 2013-05-10 10:22:23

1

你'大概在寻找confirm

然后,confirmSubmit函数体看起来像:

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

这个工程由于事件处理程序在JavaScript中是如何工作的。确认返回true,当用户单击确定时,返回false,然后单击取消。

通过返回一个来自事件处理函数的值true/false您告诉窗口是否继续处理该事件。返回false(发生在用户单击取消时发生),告诉浏览器停止处理事件并不遵循链接。

0
<a onclick="return confirm('Are you sure?')" href="delete.php">delete</a>