我有一张表格:
<form name="myForm" id="myForm" method="post" action="someUrl.php">
...
</form>
在此表单之外是包含锚链接的div:
<a href="anotherUrl.php" onclick="document.myForm.submit();return true;">link</a>
我正在尝试提交myForm,然后再继续执行anotherUrl.php。但它所做的只是重定向到anotherUrl.php而不提交myForm。帮助
答案 0 :(得分:2)
尝试:
onclick="document.forms['myForm'].submit(); return false;"
无论如何,返回true将是多余的。
您需要从someUrl.php重定向 - 可能使用:
header("Location: http://domain.com/anotherUrl.php");
exit();
答案 1 :(得分:-1)
您使用的是任何javascript框架吗?通过使用jquery或创建一个将触发表单提交然后重定向的函数,您将更容易实现。