我用动态表创建了一个简单的表单。此表行按用户输入值递增,因此每次创建新行时我都需要递增组合框或select(选项),因此它应该像默认的组合框值。注意:此选择或组合框是列属性的一部分,请记住行增量,但没有列。
第二个问题:
我希望收集此表列数据或值,无论其行号是什么,并使用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/>
答案 0 :(得分:3)
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 []'作为范围。也改变了功能
重命名代码保存,你知道如你所说。使用数组变量保存在数据库中