doujie2356
2014-10-06 09:11 阅读 74

在新的浏览器/窗口上点击提交按钮后打开PHP操作

Good Day, I am trying to make this code run on a new window; Below is my code:

TEST1.PHP

<html><head>

<script>
    function submitForm(action)
    {
        document.getElementById('1').action = action;
        document.getElementById('1').submit();
    }
</script>

<title>test</title></head><body><form id="1" name="test-1" action="test3.php" method="post">
<input name="fname"><input name="lname"><br>

<input value="Save" name="save" )="" type="submit">
<input value="Nwindow" name="nwindow" onclick="submitForm('test2.php');
window.open='test2.php'" type="submit">

TEST2.PHP

<html><head>
<form id="2" name="test-2" action="test2.php" method="post">
<title>test</title></head><body>

<input name="fname" value="<?php echo $_POST['fname']; ?>">
<input name="lname" value="<?php echo $_POST['lname']; ?>">
<br>
</form>
</body></html>

They both work correctly but what i wanted for nwindow button to perform TEST2.PHP on another window/browser; I tried window open but it is not working.

I am new with javascript so i am not sure it this can be done.

Any help is much appreciated.

Thanks in Advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongwen9051 dongwen9051 2014-10-06 09:13

    Simply use target="_blank" on your first form.

    Read the manual for more info on forms: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form

    EDIT: If you want to only load the new tab for one of the submit buttons, do this:

    <form id="myForm" name="test-1" action="test3.php" method="post">
    <input name="fname"><input name="lname"><br>
    
    <input value="Save" name="save" type="button" onclick="submitForm('test3.php','_self');">
    <input value="Nwindow" name="nwindow" type="button" onclick="submitForm('test2.php','_blank');">
    

    Then in your JS:

    function submitForm(action,target)
    {
      document.getElementById('myForm').target = target
      document.getElementById('myForm').action = action;
        document.getElementById('myForm').submit();
    }
    
    点赞 评论 复制链接分享

相关推荐