admin管理员组文章数量:1426217
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 ;
}
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 ;
}
Share
Improve this question
edited May 10, 2013 at 10:07
Ankur Saxena
asked May 10, 2013 at 9:55
Ankur SaxenaAnkur Saxena
6393 gold badges13 silver badges26 bronze badges
7
- Just add a prompt in the confirmSubmit ? – JNDPNT Commented May 10, 2013 at 9:58
- I suggest you read about AJAX, mysqli and PDO. – elclanrs Commented May 10, 2013 at 9:58
-
In
confirmSubmit()
function ? – Rikesh 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. – Robert 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 thedelete.php
link is not followed – Jan Turoň Commented May 10, 2013 at 9:59
5 Answers
Reset to default 3This line will show confirm dialogbox before redirect.
<a onclick="return confirm('Are You sure?')">...</a>
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>
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.
<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"
}
}
<a onclick="return confirm('Are you sure?')" href="delete.php">delete</a>
本文标签: javascript alert before php codeStack Overflow
版权声明:本文标题:javascript alert before php code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745427048a2658162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论