我正在尝试通过单击 for 循环中的组合框来填写我的字段。我得到了这个,但只在我的一排。当我生成另一个新行时,它没有取值。单击组合键时,我有不止一行要填写该字段。我什至尝试在课堂上使用它,但它没有发生。
我的html代码是
<td align="center"><input type="text" size="6" maxlength="6" maxlength="6" id="code" name="code_0" class="code1 form-input-oth"/></td>
<script type="text/javascript">
function Expedisi(t)
{
var y = document.getElementById("code");
y.value = t.value;
}
</script>
执行此操作的 javascript 代码是:
<script type="text/javascript">
function Expedisi(t)
{
var y;
for(var i=0; i<y.length;i++){
document.getElementById("code").innerHTML=y[i];
y[i].value = t.value;
}
}
</script>
但是上面的代码不起作用。
</table>
<tr>
<table id="detail" border="1px" width="50%" >
<tr>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Sr No.</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Item Code</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Item Name</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Qty</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Cost</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Amount</font><span></span></label></td>
</tr>
<?php
if ($addflag == 0) {
$qry = mysql_query("SELECT * FROM `damtran` WHERE vouchno='$getvouch'") or die(mysql_error());
$ctr = 0;
while ($row = mysql_fetch_array($qry)) {
echo "<tr>";
echo '<td align="center"><input type="text" size="6" maxlength="6" name="sr_' . $ctr . '" value="' . $row["srno"] . '" class="form-input-oth"/></td>';
echo '<td align="center"><input type="text" size="6" maxlength="6" id="code" name="code_' . $ctr . '" value="' . $row["code"] . '" class="code1 form-input-oth"/> </td>';
echo '<td align="center"><select data-placeholder="Item Name" id="cmbitem" style="width:200px; text-align: left;" name="cmbitem_' . $ctr . '" onChange="Expedisi(this);" class="chzn-select-deselect" >';
echo "<option value=$geti[code]>$geti[name]</option>";
$iqry = mysql_query("SELECT * FROM `item` ") or die(mysql_error());
while ($trow = mysql_fetch_array($iqry)) {
echo "<option value=$trow[code]>$trow[name]</option>";
}
echo '</select></td>';
echo '<td align="center"><input type="text" size="6" maxlength="6" name="qty_' . $ctr . '" value="' . $row["qty"] . '" class="qty form-input-oth"/></td>';
echo '<td align="center"><input type="text" size="6" maxlength="6" name="cost_' . $ctr . '" value="' . $row["cost"] . '" class="cost form-input-oth"/></td>';
echo '<td align="center"><input type="text" size="9" maxlength="6" id="amt" name="amt_' . $ctr . '" value="' . $row["amt"] . '" class="cal form-input-amt"/></td>';
echo '</tr>';
$ctr++;
}
} else {
?>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" maxlength="6" name="sr_0" class="form-input-oth"/></td>
<td align="center"><input type="text" size="6" maxlength="6" maxlength="6" id="code" name="code_0" class="code1 form-input-oth"/></td>
<td align="center"><select data-placeholder="Item Name" style="width:200px; text-align: left;" name="cmbitem_0" onChange="Expedisi(this)" class="chzn-select-deselect" >
<option value=""></option>
<?php
$iqry = mysql_query("SELECT * FROM `item` ") or die(mysql_error());
while ($trow = mysql_fetch_array($iqry)) {
echo "<option value=$trow[code]>$trow[name]</option>";
}
?>
</select></td>
<td align="center"><input type="text" size="6" maxlength="9" name="qty_0" class="qty form-input-oth"/></td>
<td align="right"><input type="text" size="6" maxlength="9" name="cost_0" class="cost form-input-oth"/></td>
<td align="right"><input type="text" size="6" maxlength="9" id="amt" name="amt_0" class="cal form-input-amt"/></td>
</tr>
<?php } ?>
</table>
<tr>
<td>
<input type="button" id="addnew" class="classname" name="addnew" value="+" />
<input type="hidden" id="items" name="items" value="<?php echo ($addflag == 0) ? $ctr : 1; ?>" />
</td>
</tr>