我创建了一个带有动态表的简单表单。此表行由用户输入值递增,因此每次创建新行时我都需要递增组合框或选择(选项),因此它应该类似于默认组合框值。注意:这个选择或组合框是列属性的一部分,记住行增量,但没有列。
第二个问题:
我想收集这个表的列数据或值,无论它的行数是多少,并使用 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/>