Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 一次输入两个表单_Javascript_Php_Html - Fatal编程技术网

Javascript 一次输入两个表单

Javascript 一次输入两个表单,javascript,php,html,Javascript,Php,Html,我想知道我如何才能使这项工作,不幸的是,我的代码不工作。我希望我的表单有两个按钮;一个转到另一个PHP文件,另一个转到另一个PHP文件 第一个按钮“提交”工作正常。但是第二个按钮,见RANK,不起作用,点击后什么也没发生 <section class="small-section bg-gray-lighter" id="start"> <div class="container relative">

我想知道我如何才能使这项工作,不幸的是,我的代码不工作。我希望我的表单有两个按钮;一个转到另一个PHP文件,另一个转到另一个PHP文件

第一个按钮“提交”工作正常。但是第二个按钮,见RANK,不起作用,点击后什么也没发生

 <section class="small-section bg-gray-lighter" id="start">
                    <div class="container relative">

                        <!-- FORMS -->
                        <form id="format" class="form align-center" action="Algorithms/article.php" method = "GET">  
                           <form id="rank" class="form align-center" action="Algorithms/Main2.php"  method = "GET">
                            <div class="row">
                                <div class="col-md-8 align-center col-md-offset-2">

                                    <div class="newsletter-label font-alt">
                                        Type the description of your case below
                                    </div>

                                    <div class="mb-20">

                                        <!-- INPUT TEXT FIELD -->
                                        <input placeholder="Start typing here" name = "caseInput" class="newsletter-field form-control input-md round mb-xs-12"  type="text"  required/>

                              </form>
                           </form>
                                       <!-- BUTTONS -->
                                        <button form="format" type="submit" class="btn btn-mod btn-medium btn-round mb-xs-10">
                                            Submit
                                        </button> 
                                        <button form="rank" type="submit" class="btn btn-mod btn-medium btn-round mb-xs-10">
                                            See rank
                                        </button> 

                                        <!-- END OF BUTTONS -->
                                    </div>
                                    <div class="form-tip">
                                        <i class="fa fa-info-circle"></i> Ex. "The father killed her daughter."
                                    </div>

                                    <div id="subscribe-result"></div>

                                </div>
                            </div>
                        </div>
                    </section>

请在下面键入您的案例描述
提交
参见排名
父亲杀了她的女儿
看起来是这样的:

来自

表单
不得包含其他
表单
元素


使用javascript函数更改表单操作的实现示例:

<html>
    <body>

        <script>
            function mySubmit(wtf) {
              if ('article' == wtf ) {
                  document.forms['myForm'].action = 'Algorithms/article.php';
              } else if ('Main2' == wtf ) {
                  document.forms['myForm'].action = 'Algorithms/Main2.php';
              } else
                  return false;

              document.forms['myForm'].submit();
            }
        </script>

        <form name="myForm">
            <input type ="button" value="submit article" class="btn btn-mod btn-medium btn-round mb-xs-10" onClick="mySubmit('article')">
            <input type ="button" value="submit Main2" class="btn btn-mod btn-medium btn-round mb-xs-10" onClick="mySubmit('Main2')">
        </form>

    </body>
</html> 

函数mySubmit(wtf){
如果('article'==wtf){
document.forms['myForm'].action='Algorithms/article.php';
}否则如果('Main2'==wtf){
document.forms['myForm'].action='Algorithms/Main2.php';
}否则
返回false;
document.forms['myForm'].submit();
}
来自

表单
不得包含其他
表单
元素


使用javascript函数更改表单操作的实现示例:

<html>
    <body>

        <script>
            function mySubmit(wtf) {
              if ('article' == wtf ) {
                  document.forms['myForm'].action = 'Algorithms/article.php';
              } else if ('Main2' == wtf ) {
                  document.forms['myForm'].action = 'Algorithms/Main2.php';
              } else
                  return false;

              document.forms['myForm'].submit();
            }
        </script>

        <form name="myForm">
            <input type ="button" value="submit article" class="btn btn-mod btn-medium btn-round mb-xs-10" onClick="mySubmit('article')">
            <input type ="button" value="submit Main2" class="btn btn-mod btn-medium btn-round mb-xs-10" onClick="mySubmit('Main2')">
        </form>

    </body>
</html> 

函数mySubmit(wtf){
如果('article'==wtf){
document.forms['myForm'].action='Algorithms/article.php';
}否则如果('Main2'==wtf){
document.forms['myForm'].action='Algorithms/Main2.php';
}否则
返回false;
document.forms['myForm'].submit();
}

表单中不能有表单。(这就是为什么你的第二个buton不起作用)

因此,您的解决方案是在表单中有两个名称不同的“submit”元素。然后,在表单提交时,根据按下的按钮进行相应的检测和处理

 <!-- BUTTONS -->
 <input type="submit" name='submitAction1' class="btn..." value='Submit'>
 <input type="submit" name='submitAction2' class="btn..." value='See rank'>

表单中不能有表单。(这就是为什么你的第二个buton不起作用)

因此,您的解决方案是在表单中有两个名称不同的“submit”元素。然后,在表单提交时,根据按下的按钮进行相应的检测和处理

 <!-- BUTTONS -->
 <input type="submit" name='submitAction1' class="btn..." value='Submit'>
 <input type="submit" name='submitAction2' class="btn..." value='See rank'>

首先,在
中使用
是没有意义的。有两种方法可以做到这一点:

方法1

使用2个表格代替

<form method="post" action="php_file_1.php" id="form1">
    <!-- Your further HTML Code Goes Here...   -->
</form>
<form method="post" action="php_file_2.php" id="form2">
    <!-- Your further HTML Code Goes Here...   -->
</form>

首先,在
中使用
是没有意义的。有两种方法可以做到这一点:

方法1

使用2个表格代替

<form method="post" action="php_file_1.php" id="form1">
    <!-- Your further HTML Code Goes Here...   -->
</form>
<form method="post" action="php_file_2.php" id="form2">
    <!-- Your further HTML Code Goes Here...   -->
</form>

请更具体一点,到底是什么不起作用?@bkausbk,第一个按钮工作正常。但另一个按钮“查看排名”不可点击。请不要在表单内调用表单。使用jQuery,您可以更改表单的操作,然后两者都可以使用。您的HTML乱七八糟。先把它清理一下。请说得更具体一些,到底是什么不起作用?@bkausbk,第一个按钮工作正常。但另一个按钮“查看排名”不可点击。请不要在表单内调用表单。使用jQuery,您可以更改表单的操作,然后两者都可以使用。您的HTML乱七八糟。先把它清理干净。