douqi1212 2017-03-10 20:44
浏览 65
已采纳

表单HTML5和PHP&Javascript选项卡

This is the two code I have for one of my projects. The goal of this project is to have first page send information that opens into a new tab with the message from the information selected in the form. I am not fimilair with coding that much so my question is the following:

When I click submit the php page will open in a new tab showing the message and information. How do I or what direction should I look into to achieve the following tasks:

  • click submit => open new tab with the php page
  • click submit again => refreshes the php page tab that's already open with the updated information without opening up a new tab.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <script language="javascript" type="text/javascript">
            function dynamicdropdown(listindex) {
              document.getElementById('senator').className = listindex;
            }
            
            </script>
      
            <style>
            optgroup {
              display: none;
            }

            select.agriculture 
            optgroup.agriculture
      {
              display: block;
            }
            
            div#header{
            padding: 1px;
            color: yellow;
            padding-left: 9px;
            background-color: #000080;
            }
            
            .room130{
            padding: 9px;
            float: left;
            width: 50%;
            }
    
            </style>
    </head>
    
<body>

    <div class="header" id="header">
    <h1>test header</h1>
    </div>

    <div class="room130">
    <h3>Room 130</h3>
    <form target="_blank" action = "room130.php" method="POST">
        <div class="category_div" id="category_div">Committee:
            <select id="committee" name="committee" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
                <option value="">Select Committee</option>
                <option value="agriculture">AGRICULTURE</option>
            </select>
        </div>
        
        <br>
        
        <div class="sub_category_div" id="sub_category_div">
        Individual:
            <select name="senator" id="senator">
                <option value="">Select individual</option>
                    <optgroup class="agriculture">
                        <option value="the chair">THE CHAIR</option>
                        <option value="the presenter">THE PRESENTER</option>
                        <option value="test">test</option>
                        <option value="test">test</option>
                        <option value="test">test</option>
                        <option value="test">test</option>
                        <option value="test">test</option>
                        <option value="test">test</option>
                        <option value="test">test</option>
                        <option value="test">test</option>
                    </optgroup>
            </select>
        </div>

PHP:

<html>
    <header>
        <title>Room 130</title>


        <style>
            div {
                height: 200px;
                width: 400px;

                position: fixed;
                top: 50%;
                left: 50%;
                margin-top: -100px;
                margin-left: -200px;
                
                background-color: #000080;
                color: white;
            }
            
        </style>
    </header>

<body>

    <div class="message" id="message">
        <h2>Message <?php echo $_POST["senator"]; ?>. Thank you. </h2>
    </div>

</body>
</html>

</div>
  • 写回答

2条回答 默认 最新

  • dongsashe6006 2017-03-10 22:10
    关注

    Your second file room130.php contains next title :

    <title>Room 130</title>
    

    You can use that title as target in the <form of your first file :

                     ▼
    <form target="Room 130" action = "room130.php" method="POST">
    

    The first time the <form is submitted the target will open a new tab, if the same form is submitted again it will not open a new tab, instead it will refresh the already opened tab because it contains the title "Room 130".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号