将一行表提交给PHP脚本

时间:2017-02-24 18:26:58

标签: javascript php html html-table

我有这张桌子:

<table border>
    <tr>
        <th>Name</th>
        <th>Surname</th>
        <th>Telephone</th>
        <th>Select</th>
    </tr>
    <tr>
        <td>John</td>
        <td>Smith</td>
        <td>123456789</td>
        <td><input type = 'radio' name = 'select' value = '1' required></td>
    </tr>
    <tr>
        <td>Mary</td>
        <td>Taylor</td>
        <td>012345678</td>
        <td><input type = 'radio' name = 'select' value = '2' required></td>
    </tr>
    <tr>
        <td>Robert</td>
        <td>Lewis</td>
        <td>901234567</td>
        <td><input type = 'radio' name = 'select' value = '3' required></td>
    </tr>
</table>

它是动态生成的。

我只想提交与我按下的单选按钮关联的行到我的PHP脚本。我怎样才能(如果可能) HTML / JavaScript?

1 个答案:

答案 0 :(得分:0)

首先你需要添加onclick函数然后在函数值中添加count

<table border id="table1">
<tr>
<th>Name</th>
<th>Surname</th>
<th>Telephone</th>
<th>Select</th>
</tr>
<tr>
<td>John</td>
<td>Smith</td>
<td>123456789</td>
<td><input type = 'radio' id="id1" name = 'select' value = '1' required onclick="getAllData(1)"></td>
</tr>
<tr>
<td>Mary</td>
<td>Taylor</td>
<td>012345678</td>
<td><input type = 'radio' id="id2" name = 'select' value = '2' required onclick="getAllData(2)"></td>
</tr>
<tr>
<td>Robert</td>
<td>Lewis</td>
<td>901234567</td>
<td><input type = 'radio' id="id3" name = 'select' value = '3' required onclick="getAllData(3)"></td>
 </tr>
 </table>
  <script type="text/javascript">
   function getAllData(id_value){
   var table = document.getElementById("table1");
   FirstName = table.rows[id_value].cells[0].innerHTML;                
   LastName = table.rows[id_value].cells[1].innerHTML;
   phone = table.rows[id_value].cells[2].innerHTML;
    alert(FirstName+"=="+LastName+"=="+phone);
  window.location.href="edit.php?FirstName="+FirstName+"&LastName="+LastName+"&phone="+phone;
   }
  </script>

然后创建edit.php页面或者你可以更改页面名称然后添加这段代码,一件事页面路径需要更正

print_r($_GET);

然后您可以看到行的所有数据