admin管理员组文章数量:1289496
I have a simple form with one hidden input field, and a submit button. When the user clicks the submit button, I want it first to run a JavaScript function with a confirm() function. Depending on whether the user hits 'Ok' or 'Cancel', I want the form to submit, or to not submit. How do I successfully assign an on-click function to a submit button, and have it work as described above?
function confirmDelete() {
var del = confirm("Are you sure you wish to delete this post?");
if (del)
//continue and submit the form
else
//the form should not be submitted
}
Here is the form:
<form action="/delete/" method="post">
<input type="hidden" name="path" value="'.$path.'" />
</form>
I realize that I could scrap the form altogether and just pass the hidden variable as a GET variable to the /delete/ page, however I would prefer to use a POST variable for security reasons.
I have a simple form with one hidden input field, and a submit button. When the user clicks the submit button, I want it first to run a JavaScript function with a confirm() function. Depending on whether the user hits 'Ok' or 'Cancel', I want the form to submit, or to not submit. How do I successfully assign an on-click function to a submit button, and have it work as described above?
function confirmDelete() {
var del = confirm("Are you sure you wish to delete this post?");
if (del)
//continue and submit the form
else
//the form should not be submitted
}
Here is the form:
<form action="/delete/" method="post">
<input type="hidden" name="path" value="'.$path.'" />
</form>
I realize that I could scrap the form altogether and just pass the hidden variable as a GET variable to the /delete/ page, however I would prefer to use a POST variable for security reasons.
Share Improve this question edited Aug 22, 2012 at 3:09 Claudio Redi 68.4k15 gold badges137 silver badges160 bronze badges asked Aug 22, 2012 at 3:03 fvgsfvgs 22k9 gold badges36 silver badges49 bronze badges1 Answer
Reset to default 10This would suffice:
<input type="submit" value="Delete" onClick="return confirm('Are you sure?');" />
本文标签:
版权声明:本文标题:post - Assign JavaScript function to submit button, which should execute conditionally - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741468836a2380475.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论