dsxpt62448 2016-11-11 13:49
浏览 61

在表格中一次只提交表格[关闭]

<from>
    <table>
        <tr>
            <td><input type='text' name="emp_name"></td>
            <td><input type='text' name="emp_phone"></td>
            <td><input type='submit' name="submit"></td>
        </tr>
        <tr>
            <td><input type='text' name="emp_name"></td>
            <td><input type='text' name="emp_phone"></td>
            <td><input type='submit' name="submit"></td>
        </tr>
    </table 
</form>

When I click submit it submits only single tr data

  • 写回答

2条回答 默认 最新

  • doulidai6316 2016-11-11 13:53
    关注

    If you submit it to PHP for example, you'll be able to access it using: $_POST['emp_name']. The problem in your script is that emp_name is used several times.

    Make sure to use unique names. So your code could be (if not known with arrays):

    <form method = "POST"><table>
     <tr>
       <td><input type='text' name="emp_name_0"></td>
       <td><input type='text' name="emp_phone_0"></td>
       <td><input type='submit' name="submit_0"></td>
     </tr>
     <tr>
       <td><input type='text' name="emp_name_1"></td>
       <td><input type='text' name="emp_phone_1"></td>
       <td><input type='submit' name="submit_1"></td>
     </tr>
    </table>
    </form>
    

    Now they're unique and you can access them by name without any problems. But probably you want one button for each form. Then just close the form after the submit button, and directly open a new form

    <form>/*form 1*/</form> and <form>/*form 2*/</form>
    

    Set a method for your form. in this case POST you want to post data, then you need a php file that will handle the form submition

    <?php
    
    if(isset($_POST['submit_0'])){
    
    //First button is clicked handle it.
    
    }elseif(isset($_POST['submit_1'])){
    
    // handle the second button
    
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了