簡體   English   中英

如何收集動態添加的行(HTML表)的值(數據)? 使用PHP和XAMPP

[英]How to collect values (data) of dynamically added rows (HTML table) ? Using php & XAMPP

我創建了帶有動態表的簡單表單。 該表行根據用戶輸入值增加,因此每次創建新行時,我都需要增加組合框或選擇(選項),因此它應該類似於默認組合框值。 注意:此選擇框或組合框是列屬性的一部分,請記住行遞增,但不包含列。

第二個問題:

我想收集此表的列數據或值(無論其行號是多少),並使用php將其存儲到XAMPP數據庫。 我知道如何從單一表單收集數據,但是我不知道如何從動態表單收集數據。

這是代碼:

function AddRows()
{
var tableelement = document.getElementById("mytable")
var rows = document.getElementById("noofrows").value;
var tablerowcount = tableelement.rows.length;
var currowcount = tablerowcount;


for(i = 1; i < rows; i++) {

var row = tableelement.insertRow(currowcount);
var cellid = row.insertCell(0);
cellid.innerHTML = "<b>" + currowcount +"</b>";
var cellid2 = row.insertCell(1);


cellid2.innerHTML = "<input value='' id='" + currowcount +"_name' /> ";
var cellid3 = row.insertCell(1);
cellid3.innerHTML = "<input value='' id='" + currowcount +"_name' /> ";
var cellid4 = row.insertCell(1);
cellid4.innerHTML = "<input value='' id='" + currowcount +"_name' /> ";
var cellid5 = row.insertCell(1);
cellid5.innerHTML = "<input value='' id='" +currowcount +"_name' /> ";
var cellid6 = row.insertCell(1);
cellid6.innerHTML = "<input value='' id='" +currowcount+"_name' /> ";


var currowcountcurrowcount = currowcount++;


}
}
</script>
</head>
<body>
<form method="post" action="insert.php>

Carton Number :<input type="text" name="cn"> <br>
Business Unit :<input type="text" name="bu"> <br>
No of Files  :<input type="noofrows" id="noofrows"  value="1" name="nof" />

<input name="add" id="add" type="button" value="Add" onClick="AddRows()"/>


<table name="mytable" id="mytable" border=1>
    <tr>
        <td>
          <b>SN</b>
        </td>
        <td>
          <b>From</b>
        </td>
        <td>
          <b>To</b>
        </td>
        <td>
          <b>Range</b>
        </td>
        <td>
          <b>Document Category</b>
        </td>
        <td>
          <b>Document Type</b>
        </td>
    </tr>
    <tr>
    <td>
      <b>1</b>
    </td>
    <td>
       <input value="" id='1_name' >
    </b>
</td>
<td>
       <input value="" id='1_name'/>
    </b>
</td>
<td>
   <input value="" id='1_name' />
 </b>
    </td>

  <td>
  <Select id='select' />
    <option name="option" value="finance">Finance Documents</option>
    <option name="option" value="hr">HR Documents</option>
    <option name="option" value="test">test</option
    </Select>
  </b>
    </td>
    <td>

    <Select id='select' />
       <option name="option" value="CP">Cash movement</option>
       <option name="option" value="PV">Payment Voucher</option>
       <option name="option" value="RV">RV</option
    </Select>
    </b>
    </td>
</tr>
</table>
<br/>
function AddRows()
{
var tableelement = document.getElementById("mytable")
var rows = document.getElementById("noofrows").value;
var tablerowcount = tableelement.rows.length;
var currowcount = tablerowcount;


for(i = 1; i < rows; i++) {

var row = tableelement.insertRow(currowcount);
var cellid = row.insertCell(0);
cellid.innerHTML = "<b>" + currowcount +"</b>";
var cellid2 = row.insertCell(1);
cellid2.innerHTML = "<Select id='select' /><option name='option' value='CP'>Cash movement</option><option name='option' value='PV'>Payment Voucher</option>   <option name='option' value='RV'>RV</option></Select> ";
var cellid3 = row.insertCell(1);
cellid3.innerHTML = "<Select id='select' /><option name='option' value='finance'>Finance Documents</option><option name='option' value='hr'>HR Documents</option><option name='option' value='test'>test</option</Select> ";
var cellid4 = row.insertCell(1);
cellid4.innerHTML = "<input value='' id='" + currowcount +"_name' /> ";
var cellid5 = row.insertCell(1);
cellid5.innerHTML = "<input value='' id='" +currowcount +"_name' /> ";
var cellid6 = row.insertCell(1);
cellid6.innerHTML = "<input value='' id='" +currowcount+"_name' /> ";


var currowcountcurrowcount = currowcount++;


}
}
</script>

更改函數以獲取每一行的選擇並保存數據,然后將所有輸入和選擇id更改為數組變量
ex id ='1_name_Range []'表示范圍。 還要更改函數重命名代碼以進行保存,正如您所說的那樣。使用數組變量保存在數據庫中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM