我有多行插入,所以,我想将它们插入数据库。 我正在尝试使用循环函数将它们发送到表中;但没有成功。请有人帮忙吗?
//Adding New Line Item Function
var i = 1;
function AddNew(){
if (i <=3){ //if you don't want limit, you remove IF condition
i++;
var div= document.createElement('div');
div.innerHTML = '<input type="text" value="'+i+'" name="lineitem_'+i+'" maxlength="2" size="2"> <input type="text" name="materialcode_'+i+'" placeholder="Material Code" maxlength="18" size="18"> <input type="text" name="qty_'+i+'" placeholder="Quantity" maxlength="10" size="10"> <input type="text" name="price_'+i+'" placeholder="Price" maxlength="10" size="10"> <input type="button" onclick="removeItem(this)" value="-">';
document.getElementById('addingitem').appendChild(div);
}
}
function removeItem(div){
//document.getElementById('addingitem').removeChild(div.parentNode);
i--;
var addingitem = document.getElementById('addingitem');
addingitem.removeChild(div.parentNode);
var inputs = addingitem.querySelectorAll('[name^="lineitem_"]');
for (var r = 0; r < inputs.length; r++)
{
var item = inputs[r];
item.value = r + 1;
}
inputs = null;
}
//Validate Number Key
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : evt.keyCode
return !(charCode > 31 && (charCode < 48 || charCode > 57));
}
&#13;
<form method="post" action="make_order.php">
<!--Adding item-->
Item Detail:
<br />
<div id="addingitem">
<input type="text" name="lineitem_1" id="item" value="1" maxlength="2" size="2">
<input type="text" name="materialcode_1" placeholder="Material Code" maxlength="18" size="18">
<input type="text" name="qty_1" placeholder="Quantity" maxlength="10" size="10">
<input type="text" name="price_1" placeholder="Price" maxlength="10" size="10">
<input type="button" name="addnew" id="Add_New()" onClick="AddNew()" value="New Item">
</div>
<br />
<input type="submit" name="makeorder" value="Make Order">
</form>
&#13;