我的php代码如下
<?php
if (isset($_POST["pitcode"]))
{
echo $_POST['pitcode'];
$pnetamt=0;
foreach ($_POST['txtwono1'] as $k => $v)
{
$pitcode=$_POST['pitcode'][$k];
$m_no=0;
$sql = mysql_query("select itrate from ITMAST where itcode='$pitcode'") or die(mysql_error());
$row = mysql_fetch_array($sql) or die(mysql_error());
$m_no = mysql_num_rows($sql);
if ($m_no!=0)
{
$sql = mysql_query("select itrate from ITMAST where itcode='$pitcode'") or die(mysql_error());
$row = mysql_fetch_row($sql);
$prate=$row[0];
}
}
}
?>
Javascript代码
<script type='text/javascript'>
function getitemcode()
{
var model=$('#itname').val();
document.frmwo.getElementById("txtitcode").value = model;
}
</script>
和HTML
<html>
<td><input type="text" maxlength="3" size="2" name="txtwono1[]" class="rightJustified" value="<?php echo $pwono1; ?>"/></td>
<td><input type="text" maxlength="2" size="2" name="txtsno[]" class="rightJustified" value="<?php echo $psno; ?>"/></td>
<td>
<?php
$sql = "SELECT itcode,itname FROM ITMAST ";
$result = mysql_query($sql) or die(mysql_error());
echo "<select name='itname[]' id='itname' onchange='getitemcode()'>";
while ($row = mysql_fetch_array($result))
{
echo "<option value = '{$row['itcode']}'";
if ($pitcode == $row['itcode'])
echo "selected = 'selected'";
echo ">{$row['itname']}</option>";
}
echo "</select>";
?>
</td>
<td><input type="text" maxlength="8" size="8" name="txtitcode" id='txtitcode' class="rightJustified" value="<?php echo $pitcode; ?>"/></td>
<td><input type="text" maxlength="8" size="8" name="txtqty[]" class="rightJustified" onchange="calcitemamt()" value="<?php echo $pqty; ?>"/></td>
<td><input type="text" maxlength="6" size="6" name="txtrate[]" class="rightJustified" disabled="disabled" value="<?php echo $prate; ?>"/></td>
<td><input type="text" maxlength="7" size="7" name="txtamt[]" disabled="disabled" class="rightJustified" value="<?php echo $pamt; ?>"/></td>
</html>
我的问题是,当我从组合中选择项目时,其值不会传递给我从中获取该项目价格的PHP代码,并且该价格应该在费率列中。这适用于html表的所有行 - 如何
答案 0 :(得分:1)
更改HTML代码
echo "<select name='itname[]' id='itname' onchange='getitemcode()'>";
与
echo "<select name='itname[]' id='itname' onchange='getitemcode(this.value)'>";
也会更改javascript代码
<script type='text/javascript'>
function getitemcode()
{
var model=$('#itname').val();
document.frmwo.getElementById("txtitcode").value = model;
}
</script>
带
<script type='text/javascript'>
function getitemcode(model)
{
document.frmwo.getElementById("txtitcode").value = model;
}
</script>