Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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 - Fatal编程技术网

使用javascript乘以值

使用javascript乘以值,javascript,Javascript,我使用js进行乘法,但只有第一行被乘法,其他行没有被乘法 <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("form1", $con); error_reporting(E_ALL ^ E_NOTICE); $nam=$_REQUEST['select1']; $

我使用js进行乘法,但只有第一行被乘法,其他行没有被乘法

<?php 
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("form1", $con);


error_reporting(E_ALL ^ E_NOTICE);
$nam=$_REQUEST['select1'];


 $row=mysql_query("select * from inv where name='$nam'");
while($row1=mysql_fetch_array($row))
{ 
$Name=$row1['Name'];
    $Address =$row1['Address'];
    $City=$row1['City'];
        $Pincode=$row1['Pincode'];
    $No=$row1['No'];
    $Date=$row1['Date'];
    $DCNo=$row1['DCNo'];
    $DcDate=$row1['DcDate'];
    $YourOrderNo=$row1['YourOrderNo'];
    $OrderDate=$row1['OrderDate'];
    $VendorCode=$row1['VendorCode'];
    $SNo=$row1['SNo'];
    $descofgoods=$row1['descofgoods'];
    $Qty=$row1['Qty'];
    $Rate=$row1['Rate'];
    $Amount=$row1['Amount'];
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
 <script type="text/javascript">
       **function ram()
       {

       var q=document.getElementById('qty').value;

       var r=document.getElementById('rate').value;

       document.getElementById('amt').value=q*r;

       }**

       </script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="1315" border="0">
  <script type="text/javascript">
function g()
{
form1.submit();
}
</script>
  <tr>
    <th>Name</th>
    <th align="left"><select name="select1" onchange="g();">
      <option value="" selected="selected">select</option>
      <?php $row=mysql_query("select Name from inv ");
while($row1=mysql_fetch_array($row))
{ ?>
      <option value="<?php echo  $row1['Name'];?>"><?php echo  $row1['Name'];?></option>
      <?php } ?>
    </select></th>
  </tr>
  <tr>
    <th>Address</th>
    <th align="left"><textarea name="Address"><?php echo $Address;?></textarea></th>
  </tr>
  <tr>
    <th>City</th>
    <th align="left"><input type="text" name="City" value='<?php echo $City;?>' /></th>
  </tr>
  <tr>
    <th>Pincode</th>
    <th align="left"><input type="text" name="Pincode"  value='<?php echo $Pincode;?>'></th>
  </tr>
  <tr>
    <th>No</th>
    <th align="left"><input type="text" name="No2" value='<?php echo $No;?>' readonly="" /></th>
  </tr>
  <tr>
    <th>Date</th>
    <th align="left"><input type="text" name="Date" value='<?php echo $Date;?>' readonly="" /></th>
  </tr>
  <tr>
    <th>DCNo</th>
    <th align="left"><input type="text" name="DCNo" value='<?php echo $DCNo;?>' readonly="" /></th>
  </tr>
  <tr>
    <th>DcDate:</th>
    <th align="left"><input type="text" name="DcDate" value='<?php echo $DcDate;?>' /></th>
  </tr>
  <tr>
    <th>YourOrderNo</th>
    <th align="left"><input type="text" name="YourOrderNo" value='<?php echo $YourOrderNo;?>' readonly="" /></th>
  </tr>
  <tr>
    <th>OrderDate</th>
    <th align="left"><input type="text" name="OrderDate" value='<?php echo $OrderDate;?>' readonly="" /></th>
  </tr>
  <tr>
<th width="80">VendorCode</th>
  <th width="1225" align="left"><input type="text" name="VendorCode"  value='<?php echo $VendorCode;?>' readonly="" /></th>
</tr>
  </table>
  <table width="1313" border="0">

    <tr>
      <td width="44">&nbsp;</td>
      <td width="71">SNO</td>
      <td width="527">DESCRIPTION</td>
      <td width="214">QUANTITY</td>
      <td width="214">RATE/UNIT</td>
      <td width="217">AMOUNT</td>
    </tr>
                <?php $i=1;  
        $row=mysql_query("select * from inv where Name='$nam'");
while($row1=mysql_fetch_array($row))
{ 
$descofgoods=$row1['descofgoods'];
    $Qty=$row1['Qty'];
    $Rate=$row1['Rate'];
    $Amount=$row1['Amount'];
?>
    <tr>
      <td><input type="checkbox" name="checkbox" value="checkbox" /></td>
      <td><input type="text" name="No" value='<?php echo $No;?>' readonly=""/></td>
      <td><input type="text" name="descofgoods" value='<?php echo $descofgoods;?>' /></td>
      <td><input type="text" name="qty" maxlength="50000000" id="qty"/></td>
      <td><input type="text" name="Rate"  value='<?php echo $Rate;?>' id="rate" onclick="ram()";></td>
      <td><input type="text" name="Amount"   id="amt"/></td>
    </tr>
     <?php  $i++;} ?>
    <tr>
      <th colspan="2"><a href="pp.php?msg=<?php echo $nam;?>">Print</a></th>
    </tr>
  </table>
  <label></label>
</form>
</body>
</html>

我没有阅读您的所有代码,但我认为问题在于您的标记id必须是唯一的

var q=document.getElementById('qty').value;

var r=document.getElementById('rate').value;

document.getElementById('amt').value=q*r;
javascript没有得到另一个标记,因为您有多个id为“qty”、“rate”、“amt”的标记,所以javascript只转换页面上第一个标记,并且只转换多个标记

为了避免这种情况,您应该确保每个标签的id必须是唯一的

编辑

1] 像这样更改javascript函数

   function ram(id)
   {

   var q=document.getElementById('qty_'+id).value;

   var r=document.getElementById('rate_'+id).value;

   document.getElementById('amt_'+id).value=q*r;

   }
2] 为每个标记添加后缀$i

<td><input type="text" name="qty" maxlength="50000000" id="qty_<?PHP echo($i) ?>"/></td>
      <td><input type="text" name="Rate"  value='<?php echo $Rate;?>' id="rate_<?PHP echo($i) ?>" onclick="ram('<?PHP echo($i) ?>')";></td>
      <td><input type="text" name="Amount"   id="amt_<?PHP echo($i) ?>"/></td>

我没有阅读您的所有代码,但我认为问题在于您的标记id必须是唯一的

var q=document.getElementById('qty').value;

var r=document.getElementById('rate').value;

document.getElementById('amt').value=q*r;
javascript没有得到另一个标记,因为您有多个id为“qty”、“rate”、“amt”的标记,所以javascript只转换页面上第一个标记,并且只转换多个标记

为了避免这种情况,您应该确保每个标签的id必须是唯一的

编辑

1] 像这样更改javascript函数

   function ram(id)
   {

   var q=document.getElementById('qty_'+id).value;

   var r=document.getElementById('rate_'+id).value;

   document.getElementById('amt_'+id).value=q*r;

   }
2] 为每个标记添加后缀$i

<td><input type="text" name="qty" maxlength="50000000" id="qty_<?PHP echo($i) ?>"/></td>
      <td><input type="text" name="Rate"  value='<?php echo $Rate;?>' id="rate_<?PHP echo($i) ?>" onclick="ram('<?PHP echo($i) ?>')";></td>
      <td><input type="text" name="Amount"   id="amt_<?PHP echo($i) ?>"/></td>
尝试使用parseInt()

document.getElementById('amt').value= parseInt(q) * parseInt(r);
尝试使用parseInt()

document.getElementById('amt').value= parseInt(q) * parseInt(r);

您遇到的问题是,对于这种有多行的情况,您使用了
getElementById
。Id应该是唯一的,因此在使用getElementById时,它只能获得“第一个”匹配项

您遇到的问题是,在有多行的情况下使用
getElementById
。Id应该是唯一的,因此在使用getElementById时,它只能获得“第一个”匹配项

是的,可能就是这样。尝试向所有元素添加后缀,这样就不会重复任何内容,例如:id=“amt-”是的,可能就是这样。尝试为所有元素添加后缀,这样就不会重复任何内容,例如:id=“amt-”请更清楚地说明问题。请更清楚地说明问题。