php 二级下拉框+文本框联动

3 篇文章 0 订阅

我的实例如下:

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<script   language   =   "JavaScript">
  var  onecount;
  onecount=0;
  var  onecount1;
  onecount1=0;
  var subcat = new Array();
  var array = new Array();
  <?php
  //查询商品填充商品各种信息文本框中
include '../conn/conn.php';
$sql1="select * from Tb_Goods ";
$result1 = mysql_query($sql1,$conn);
$count1 = 0;
while($res1 = mysql_fetch_array($result1))
 {
?>
array[<?php echo $count1;?>] = new Array("<?php echo $res1[GoodName];?>","<?php echo $res1[GoodNorms];?>","<?php echo $res1[GoodUnit]?>","<?php echo $res1[GoodOPrice];?>","<?php echo $res1[GoodId];?>");
 <?php
 $count1++;
 } 
 echo   "onecount1=$count1";
?> 
  <?php 
  //查询库存中商品名称
 include '../conn/conn.php';
  $sql="select * from Tb_Reserve ";
  $result = mysql_query($sql,$conn);
  $count = 0;
  while($res = mysql_fetch_array($result))
  {
  ?>
  /*
 *将读取的数据到三维数组中,商品名称、商品名称、仓库名称
  */
  subcat[<?php echo $count;?>] = new Array("<?php echo $res[GoodName];?>","<?php echo $res[GoodName];?>","<?php echo $res[StorageName]?>");
  <?php
  $count++;
  } 
  echo   "onecount=$count";
 ?>
 
function changelocation(locationid)
  {
  document.form1.goods.length =1;//从选择1开始
      var locationid=locationid;
      var i;
      for(i=0;i<onecount;i++)
       {
              //判断从第一个select(仓库中)选择的value与数组中的仓库名称是否一致
          if(subcat[i][2] == locationid)
           { 
              //将   商品名称分别添加到option中的  value与text  
            document.form1.goods.options[document.form1.goods.length]  =  new Option(subcat[i][1],subcat[i][0]);
            }
       }
 }
 function change(value1)
 {
    var value1=value1;
    var i;
    for(i=0;i<onecount1;i++)
      {     
           if(array[i][0] == value1)
            {   
             //将从数组中对应的值赋给从form中获取的元素的值
           document.getElementById("goodnorm").value= array[i][1]; 
           document.getElementById("goodunit").value= array[i][2];
           document.getElementById("goodoprice").value= array[i][3]; 
           document.getElementById("goodid").value= array[i][4]; 

             }
        }
}

  </script>

</head>
<body>
<form name="form1" action="add_sale.php" method="post">
<?php include '../limitassign.php';
if($qx15=="1"){
?>
<table>
<tr><td>所出仓库</td>
<td> <select name="storage" onChange="changelocation(document.form1.storage.options[document.form1.storage.selectedIndex].value)">
<?php
//仓库选择:
 include '../conn/conn.php';
 $result2=mysql_query("select * from Tb_Storage",$conn);
 $storage=mysql_fetch_array($result2);
 if($storage==FALSE) {
?>
<option value="0" selected>-添加仓库-</option>
 <?php   }
   else {
?>
<option value="0" selected>-选择仓库-</option>
<?php
 do{
?>
<option value='<?php echo $storage[StorageName];?>'><?php echo $storage[StorageName];?></option>
<?php
 }while ($storage=mysql_fetch_array($result2));
 }
?>
</select></td>
</tr>
<tr><td>商品名称</td>
<td>
<select name="goods" onChange="change(document.form1.goods.options[document.form1.goods.selectedIndex].value)" >
<option value="0" selected>-选择商品-</option>
</select>
</td></tr>
<tr><td>产品编号</td><td><input type="text" name="goodid" id="goodid" style="width:200px" readonly="readonly" ></td></tr>
<tr><td>产品规格</td><td><input type="text" name="goodnorm" id="goodnorm" style="width:200px" readonly="readonly"></td></tr>
<tr><td>产品单位</td><td><input type="text" name="goodunit"  id="goodunit"  style="width:200px" readonly="readonly"></td></tr>
<tr><td>销售单价</td><td><input type="text" name="goodoprice" id="goodoprice" style="width:200px" readonly="readonly"></td></tr>
<tr><td>销售数量</td><td><input type="text" name="goodcount" style="width:200px"></td></tr>
<tr>
<td><input type="submit" name="tijiao" value="添加"> </td><td><input  type="reset" value="重写"></td>
</tr>

</table>
<?php 
}
else {
 echo "<script language='javascript'>alert('对不起,您对此操作没有权限!');history:back();</script>";
 exit;
}
?>
</form>

</body>
</html>

希望以上代码对大家有用。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值