开发者

How can I submit a form to two different pages (not at same time)?

I need to submit a page to two pages depending on which button is triggering the submit. Both pages needs to be able to pick up the $_POST data being sent. This is what I have so far, but it's not working.

<form name="user" action=开发者_StackOverflow社区"" method="POST">
  <textarea name="tname" id="tname"></textarea>
  <input type='button' value='Submit'
    onclick="document.user.action='edit.php'; document.user.submit(); this.form.target='_self'; return true;">
  <input type='button' value='Preview'
    onclick="document.user.action='preview.php'; document.user.submit(); this.form.target='_blank'; return true;">
</form>

Both pages are opening in the same window (preview button should be opening in a new window).


Setting the target the same way you set the action, and setting it before you submit the form works for me:

<form name="user" action="" method="POST">
<textarea name="tname" id="tname"></textarea>
<input type='button' value='Submit'
       onclick="document.user.action='edit.php'; document.user.target='_self'; document.user.submit(); return true;">
<input type='button' value='Preview'
       onclick="document.user.action='preview.php'; document.user.target='_blank'; document.user.submit(); return true;">
</form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜