我正在尝试运行一个调用一些Javascript来询问问题的函数"你确定要删除这个客户吗?"但我的java脚本链接似乎不起作用。我在Java脚本端得到的只是删除这个词。它应该询问他们是否确定,如果没有将它们返回到他们点击的页面。如果他们确定,则删除数据。
此脚本会检查以确保没有其他数据连接到客户的数据。如果有,则不允许删除它。但如果没有任何附加条件,他们可以删除它,但我想确保他们想要做的事情。
我认为我的问题出在我的链接中,但不确定。
function checkcustomeruse($custid,$pid,$name){{}
global $db;
$sql = "SELECT COUNT(*) from signings WHERE pid = ? AND custid = ?";
$stmt = $db->prepare($sql);
$stmt->bindParam(1, $pid, PDO::PARAM_INT);
$stmt->bindParam(2, $custid, PDO::PARAM_STR);
$stmt->execute();
$number_of_rows = $stmt->fetchColumn();
$number = $number_of_rows;
if($number == 0)
{
echo '<a href="javascript: deleteAlert(custid =' . $custid . ',' . 'name =' . $name . ');">Remove</a>';
}
else
{
$Message = 'You can not delete this customer because it has signings attached to it.';
header("Location: viewallcustomer.php?Message=" . urlencode($Message));
}
}
这是javascript
function deleteAlert(custid,name){
var conBox = confirm("Are you sure you want to delete: " + name);
if(conBox){
location.href="formpross.php?processtp=deletecustomers&delete=yes&custid";
}else{
return;
}
}
答案 0 :(得分:0)
function deleteAlert(custid,name){
var conBox = confirm("Are you sure you want to delete: " + name);
if(conBox){
location.href="formpross.php";
}
return conBox;
}
答案 1 :(得分:0)
尝试以不同的方式回显您的Javascript功能。转义的单引号转换为我们发送到javascript函数的值周围的单引号。
echo '<a href="javascript: deleteAlert( \'' . $custid . '\',\'' . $name . '\');">Remove</a>';
此外,如果Javascript函数导致取消操作,我们需要返回false。
function deleteAlert(custid,name){
var conBox = confirm("Are you sure you want to delete: " + name);
if(conBox){
location.href="formpross.php?processtp=deletecustomers&delete=yes&custid";
} else {
return false;
}
}