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

时间:2017-02-10 02:24:47

标签: javascript html forms tabular

你可能会问为什么要这样做? 我的实际代码,比这个更复杂,让我们说我对我来说已经足够困难,因为这些输入在表格的不同列中分开, 并且我试图提交所有文本值的输入。

  <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>

我知道这段代码没有按照我希望的方式工作。 有什么其他可能的方法呢? Source

2 个答案:

答案 0 :(得分:1)

您不应该有多个具有相同ID的<form>个标签。你可以在表单标签中包含你想要的任何东西,所以我不确定你为什么认为你需要分解它...但这是不必要的,可能是导致你的问题的原因。

您还可以使用提交按钮的正确类型按钮完全摆脱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>

答案 1 :(得分:0)

 ******?><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******