Javascript HTML,为不同的输入文本编写脚本,但作为一个文本提交

Javascript HTML,为不同的输入文本编写脚本,但作为一个文本提交,javascript,html,forms,tabular,Javascript,Html,Forms,Tabular,你可能会问为什么要这样做? 我的实际代码,比这个复杂得多,就说我把它弄得够难了,因为这些输入在表的不同列中分开, 我正在尝试提交所有文本值的输入 <form id="myForm" action="form_action.asp"> First name: <input type="text" name="fname"><br> Last name: <inp

你可能会问为什么要这样做? 我的实际代码,比这个复杂得多,就说我把它弄得够难了,因为这些输入在表的不同列中分开, 我正在尝试提交所有文本值的输入

  <form id="myForm" action="form_action.asp">
   First name: <input type="text" name="fname"><br>
   Last name: <input type="text" name="lname"><br>
   Nick name: <input type="text" name="nname"><br>
   In Game name: <input type="text" name="iname"><br>
    </form>
        <?-----separate information ----?>
    <form id="myForm" action="form_action.asp">
    Username: <input type="text" name="uname"><br><br>
    <input type="button" onclick="myFunction()" value="Submit form">
    </form>

     <script>
     function myFunction() {
        document.getElementById("myForm").submit();
    }
    </script>

名字:
姓氏:
昵称:
游戏名称:
用户名:

函数myFunction(){ document.getElementById(“myForm”).submit(); }
我知道这段代码没有按我希望的方式工作。 还有什么其他可能的方法可以做到这一点?

您不应该有多个ID相同的
标记。您可以在表单标记中包含任何您想要的内容,因此我不确定您为什么认为需要将其拆分。。。但这是不必要的,很可能是什么导致了你的问题

您还可以通过为submit按钮使用适当的类型按钮来完全摆脱JavaScript

<form id="myForm" action="form_action.asp">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  Nick name: <input type="text" name="nname"><br>
  In Game name: <input type="text" name="iname"><br>

       <?-----separate information ----?>

   Username: <input type="text" name="uname"><br><br>
<input type="submit" value="Submit form"/>
   </form>

名字:
姓氏:
昵称:
游戏名称:
用户名:


******?>它不工作了?您是否在测试页面中链接到W3CSS?您不需要提交多个表单,您需要将它们合并到一个表单中。我的意思是,他们甚至指向同一个
动作
/目的地。也许你需要重新评估你想做什么。那么,在同一个地方发布不同的表单时,您实际上想做什么呢?ID在文档中应该是唯一的。因此,不能有多个ID相同的元素。请在同一表单中添加所有这些输入字段。您将在后端将它们集合在一起。如果您想将它们分开,您可能需要使用表单数据操作数据和表单JSON对象,并使用ajax提交数据。这并不能按您的要求工作。[链接]()在浏览器中是这样的。
 ******?><form method='POST'><?php
                echo "
                <tr>
                <td><input type='text'  name='LNS' value='$row0[1]' style='width: 100.2222204208374px;'></td>
                <td><input type='text'  name='FNS' value='$row0[2]' style='width: 100.2222204208374px;'></td>
                <td><input type='text'  name='CRS' value='$row0[3]' style='width: 60.2222204208374px;'></td>";
                if($row0[4] == "1"){
                    $str=$row0[4].'st Year';
                }else if($row0[4] == "2"){
                    $str=$row0[4].'nd Year';
                }else if($row0[4] == "3"){
                    $str=$row0[4].'rd Year';
                }else{
                    $str=$row0[4].'th Year';
                }
                echo"<td>
                <input type='text' value='$str' style='width:75.2222204208374px;'></td>";?>
                <td align="center" style="border-right-width: 10px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;padding-top: 0px;">
                <div class="image-holder" style="margin-top: 0px;margin-left: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;">
                <img class="thumbnail" src="phone.png" style="width:32px;height:32px;">
                    <div class="dropdown" style="left: 0px; width: 300px;bottom: 100px;left: 50px;">
                        <div class="dropdown-content" style="width: 300px;background-color: #E6E6E6;">
                <?php
                $q1 = "SELECT DISTINCT StudentNumber FROM `studentno` JOIN`students` ON studentID_FK=$row0[0] ";
                $r1 = mysqli_query($connection,$q1);
                echo "<b>$row0[1]'s Contact Numbers</b>";
                if(mysqli_num_rows($r1) > 0){
                while($ro1 = mysqli_fetch_row($r1)){ 
                    echo "<form method='POST'>
                    <input type='hidden' name='ID' value='$row0[0]'>
                    <input type='hidden' name='SS' value='$row0[6]'>
                    <input type='text'  name='Number' value='$ro1[0]' 
                    style='width: 136.2222204208374px;'>
                    <input type='submit' name='CHNGStdn' id='edit-icon'  alt='Submit'></input>
                    <input type='submit' name='DELStdn' id='delete-icon' alt='Submit'></input></form>";
                    }
                    echo "<form method='POST'>
                    <input type='hidden' name='ID' value='$row0[0]'>
                    <input type='hidden' name='SS' value='$row0[6]'>
                    <input type='text' name='Number' value='New'
                    style='width: 136.2222204208374px;'>
                    <input name='ADDStdn' type='submit'  id='add-icon' alt='Submit'></input><br></form>";
                    }else{
                    echo "<form method='POST'>
                    <input type='hidden' name='ID' value='$row0[0]'>
                    <input type='hidden' name='SS' value='$row0[6]'>
                    <input type='text' name='Number' value='New'
                    style='width: 136.2222204208374px;'>
                    <input name='ADDStdn' type='submit'  id='add-icon' alt='Submit'></input><br></form>";
                    }?>
                </div>
                </div>
                </div>
                </td>
                <?php 
                echo "<td><input type='text'  name='ADDR' value='$row0[5]' style='width: 136.2222204208374px;'></td>";?>
                <td>
                <?php
                $q2 = "SELECT ParentID, LastName_Parent FROM `parents`";
                $r2 = mysqli_query($connection,$q2);
                if(mysqli_num_rows($r2) > 0){
                    echo "<input type='text' style='width: 136.2222204208374px;' name='ID' value='LastName'>";      
                    while($ro2 = mysqli_fetch_row($r2)){
                        echo "";    
                    }
                }echo "</td><td>";
                    echo "
                    <input type='hidden' name='IDS' value='$row0[0]'>
                    <input type='hidden' name='SS' value='$row0[6]'>
                    <input type='hidden' name='YR' value='$row0[4]'>
                    <input type='submit' name='CHNGStd' id='edit-icon' alt='Submit'></input>";
                    ?></form><?php******