0

我正在构建一个运输表格,并编写了一个 php 页面来查询 mysql 数据库以获取销售订单并显示该订单中的每个行项目。然后,我希望能够为每个行项目添加一个框号(其中包含产品的物理框的编号)。例如,订单项 #1 用于 15 件产品 A。如果一个盒子包含两件产品 A,而我要运送 8 个零件或四个盒子,我希望能够添加一行,输入盒子编号并继续为订单项 #2 做类似的事情。

到目前为止,这是我所拥有的:

<script language="javascript">
      // Last updated 2006-02-21
function addRowToTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);

  // Item cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellLeft.appendChild(textNode);

  // Cust PN cell
  var cellBox_Num = row.insertCell(1);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'Box_Num[]';
  el.id = 'Box_Num' + iteration;
  el.size = 18;

  el.onkeypress = keyPressTest;
  cellBox_Num.appendChild(el);
}
function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}
function removeRowFromTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 1) tbl.deleteRow(lastRow - 1);
}

    </script>

//define variables and some other form stuff

$i=0;
$n=1;

while($i < $num1) {

$SO_Line_Item=mysql_result($result1,$i,"SO_Line_Item");
$My_PN=mysql_result($result1,$i,"My_PN");
$My_PN_Rev=mysql_result($result1,$i,"My_PN_Rev");
$Cust_PN=mysql_result($result1,$i,"Cust_PN");
$Cust_PN_Rev=mysql_result($result1,$i,"Cust_PN_Rev");
$Description=mysql_result($result1,$i,"Description");
$SOItemQty=mysql_result($result1,$i,"Qty");
$UOM=mysql_result($result1,$i,"UOM");
$Program=mysql_result($result1,$i,"Program");
$Required_Date=mysql_result($result1,$i,"Required_Date");   
$SOItemShipQty=mysql_result($result2,$i,"count(My_SN)"); 

?>
<tr>
<td width="3px" valign="top" align="center"><?php
echo "$SO_Line_Item";?>
</td>
<td nowrap="nowrap" valign="top" align="center"><?php
echo "$Cust_PN - $Cust_PN_Rev";?>
</td>
<td nowrap="nowrap" valign="top" align="center"><?php
echo "$My_PN - $My_PN_Rev";?>
</td>
<td nowrap="nowrap" valign="top" align="center"><?php
echo "$Description";?>
</td>
<td nowrap="nowrap" valign="top" align="center">
<?php
echo "$SOItemQty";?>
</td>
<td nowrap="nowrap" valign="top" align="center">
<?php
echo "$UOM";?>
</td>
<td nowrap="nowrap" valign="top" align="center">
<?php
echo $SOItemQty - $SOItemShipQty;?>
</td>
<td nowrap="nowrap" valign="top" align="center">
<input size="2" align="right" type="text" name="Qty">
</td>
<td nowrap="nowrap" valign="top" align="center">
<?php
echo "$Required_Date";?>
</td>
<td nowrap="nowrap" valign="top" align="center">
<?php
echo "$Program";?>
</td>
</tr>
<tr>
<td colspan="10">
<p>
<input type="button" value="Add" onclick="addRowToTable();" />
<input type="button" value="Remove" onclick="removeRowFromTable();" />
<!-- 
<input type="button" value="Submit" onclick="validateRow(this.form);" />
<input type="checkbox" id="chkValidate" /> Validate Submit  
-->
<b><font color="RED">Add/Remove Box Number For This Line Item</font></b>
</p>
</td>
</tr>

<tr>
<td></td>
<td>
<table id="tblSample">
<tr>
    <td>1</td>
    <td><input type="text" name="Box_Num[]"
     id="Box_Num1" size="18" onkeypress="keyPressTest(event, this);" /></td>

  </tr>
</table>
</td>
</tr>
<?php



$i++;
}

我能够很好地创建表单,但是我的添加和删除按钮都会影响循环的第一个实例。这是可以理解的,因为循环中所有实例的表 ID 都是“tblSample”。我不知道如何为循环的每个实例使我的 Javascript 动态化。

4

0 回答 0