2013-02-18 77 views
0

我试图使用onsubmit="return confirm('Do you really want to submit the form?')"警告出现在用户通过单击提交按钮删除项目之前。我无法得到一个确认框出现它只是继续直接删除该项目。无法获得确认框出现在提交

任何人都可以在我的代码中看到我可能会出错吗?我试图更改双引号和单引号,但没有努力获得确认框出现。

我的代码如下。

echo '<td> <form method="post" action="deleteassign.php" name="deleteassignform" 
id="deleteassignform" onsubmit="return confirm('Do you really want to submit the form?')">'; 
    echo '<input type="hidden" name="quizidvalue" id="quizidvalue" value="'.$sendquizid.'" />'; 
    echo '<input type="hidden" name="classidvalue" id="classidvalue" value="'.$sendclassid.'" />'; 
    echo '<input type="submit" name="deleteassignment" id="deleteassignment" value="Delete This Assignment"> </form> </td> </tr>'; 
+0

回显'$ sendquizid'时,您可能应该使用[htmlspecialchars](http://php.net/htmlspecialchars)。 – 2013-02-18 16:52:40

+0

现在你的引用发疯了,实际上你正在关闭你的'echo'语句。你应该使用'?>​​

... <?php'。 – 2013-02-18 16:53:58

回答

2

更改:

return confirm('Do you really want to submit the form?') 

return confirm(\'Do you really want to submit the form?\') 

这应该理清任何qouting问题,这给你,因为它肯定是不正确的错误。

+1

简单而完美,谢谢! – user1953507 2013-02-18 17:10:07

0

为什么不把代码直接放在按钮中?

<input type="submit" name="deleteassignment" id="deleteassignment" 
value="Delete This Assignment" onclick="return confirm('Do you really want to delete?')"> 
+0

引用仍然是错误的。现在只有在单击该按钮时才起作用,而不是在输入字段中按Enter时起作用。 – 2013-02-18 17:01:22

+0

这是不好的用户体验。为什么用户想在按下输入键时删除?此外,您的表单没有任何输入字段供用户专注!!!!!! – 2013-02-18 17:03:07

0

您的报价错误。您可以更好地使用这种形式,让所有的报价是正确的:

?><td> <form method="post" action="deleteassign.php" name="deleteassignform" 
id="deleteassignform" onsubmit="return confirm('Do you really want to submit the form?')"> 
<input type="hidden" name="quizidvalue" id="quizidvalue" value="<?= htmlspecialchars($sendquizid) ?>" /> 
<input type="hidden" name="classidvalue" id="classidvalue" value="<?= htmlspecialchars($sendclassid) ?>" /> 
<input type="submit" name="deleteassignment" id="deleteassignment" value="Delete This Assignment"> </form> </td> </tr> 
<?php 
1

为了输出...

onsubmit="return confirm('Do you really want to submit the form?')" 

...您需要正确转义在PHP端的报价。请尝试以下(注意单引号前的反斜杠):

echo '<td> <form method="post" action="deleteassign.php" name="deleteassignform" 
id="deleteassignform" onsubmit="return confirm(\'Do you really want to submit the form?\')">'; 
0

由代码输出的代码应该是这样的:

<form method="post" action="deleteassign.php" name="deleteassignform" 
id="deleteassignform" onSubmit="return confirm('Do you really want to submit the form?');"> 

注意confirm函数内引用。