Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取多行中选择选项的值_Javascript_Php_Html - Fatal编程技术网

Javascript 获取多行中选择选项的值

Javascript 获取多行中选择选项的值,javascript,php,html,Javascript,Php,Html,我的php代码如下 <?php if (isset($_POST["pitcode"])) { echo $_POST['pitcode']; $pnetamt=0; foreach ($_POST['txtwono1'] as $k => $v) { $pitcode=$_POST['pitcode'][$k]; $m_no=0;

我的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>
我的问题是,当我从Combo中选择项目时,它的值并没有传递给php代码,我从中获取该项目的价格,并且该价格应该出现在rate列中。这应该适用于html表的所有行-如何更改html代码

echo "<select name='itname[]' id='itname' onchange='getitemcode()'>";

还要更改javascript代码

<script type='text/javascript'>
      function getitemcode()
      {
      var model=$('#itname').val();
      document.frmwo.getElementById("txtitcode").value = model;
      }
</script>


在您的代码中document.frmwo.getElementById中的frmwo是什么?如果使用isset$\u POST[itemname],而不是isset$\u POST[pitcode]yes,则现在使用isset$\u POST['itname'],我如何获得当前行编号,以及如何将值分配给rate列(第4行,当前行是7行中的3行),首先查找当前行,然后从php代码中赋值感谢您的回答,但它仍然不起作用,我做了如上所述的更改我从document.frmwo.getElementByIdtxtitcode.value=model中进行了更改;到document.getElementByIdtxtitcode.value=model;现在它正在工作,但第二行的值也将到达第一行
<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>