function addTest(){
  var n = s.length;
  var s1 = "s"+(n+1);
  var s2 = "s"+(n+2);
  s[n] = s1;
  s[n+1] = s2;
  document.getElementById("add").innerHTML+="商品品牌:<select id='"+s1+"' name='sp_brand[]'><option></option></select>商品类别:<select id='"+s2+"' name='sp_class[]'><option></option></select>商品货号:<input type='text' name='shop_item[]' style=' width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;' /> 数量:<input type='text' name='shop_count[]' style=' border-bottom:1px #000000 solid;border-right:none; border-left:none; border-top:none; width:80px;'/> 单价:<input type='text' name='danjia[]' style=' border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;'/>"
  for(var i=n;i<s.length-1;i++) { 
    document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")"); 
  }
  change(n); //不知道是不是还是0
} function create(){
var _div=document.createElement("div");
document.getElementById('add').appendChild(_div);
var _select=document.createElement("select");
_div.appendChild(document.createTextNode("商品品牌:"));
_div.appendChild(_select);
_select.onchange=fish;
_select.options.add(new Option('请选择','default'));
for(var i in s1){
_select.options.add(new Option(s1[i],i));
}
var _select2=document.createElement("select");
_div.appendChild(document.createTextNode(" 商品类别:"));
_div.appendChild(_select2);
_select2.options.add(new Option('请选择','default'));
var _span=document.createElement("span");
_div.appendChild(_span);
_span.innerHTML="商品货号:<input type='text' name='shop_item[]' style=' width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;' /> 数量:<input type='text' name='shop_count[]' style=' border-bottom:1px #000000 solid;border-right:none; border-left:none; border-top:none; width:80px;'/> 单价:<input type='text' name='danjia[]' style=' border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;'/>";
}<a  onClick="create()"><font style="cursor:hand;" color="#0033CC">添加商品</font></a> <br />
为什么在另一个页面上获取不到本页的值?(红色标注的地方的值)
但是蓝色标注的地方却能获取到值,我实在找不出问题来,请大家帮忙。谢谢~~~~~
答完马上给分

解决方案 »

  1.   

    补充:
                $brand= serialize($_POST["sp_brand"]);
              $class=serialize($_POST["sp_class"]);
    这个是在另一个页面上获取值的时候,输出是空的。插入到数据库是:N;
      

  2.   

    select id='"+s1+"' 你看看页面源代码,这样写不行吧!用<%%>才好吧,
      

  3.   

    可以的
    在页面上点击它的时候
    <a  onClick="create()"> <font style="cursor:hand;" color="#0033CC">添加商品 </font> </a> <br /> 就会添加一行:
    商品品牌: <select id='"+s1+"' name='sp_brand[]'> <option> </option> </select>商品类别: <select id='"+s2+"' name='sp_class[]'> <option> </option> </select>商品货号: <input type='text' name='shop_item[]' style=' width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;' /> 数量: <input type='text' name='shop_count[]' style=' border-bottom:1px #000000 solid;border-right:none; border-left:none; border-top:none; width:80px;'/> 单价: <input type='text' name='danjia[]' style=' border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;'/>"麻烦大家再看一下谢谢
      

  4.   

    我想请问一下,用javascript 如何获取值呢?
      

  5.   

    昨天应该已经帮你解决了,今天又看到了  呵呵 再看看把,红色的地方代表取值的方法<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <script>
    function getValue(){  for(i=0;i <document.getElementsByName("brand").length;i++)
      {
    var   ddl   =   document.getElementsByName("brand")[i];
    var   aaa=ddl.options[ddl.selectedIndex].value;
         alert(aaa);
      }
    }

    function addTest(){ 
    document.getElementById("info").innerHTML+="商品品牌: <select id='s1[i]' name='brand'> <option value=1>test</option>  </select>商品类别: <select id='s2[i]' name='class[]'> <option> 3123</option> </select>商品货号: <input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' />  数量: <input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价: <input type=text id=test name=danjia style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> <br />"; 
     } 
    </script>
     </HEAD>
    <body >
    <form id="form1"> 
    <table>
    <input type="checkbox"  name="myChkbox" />check
    <br>
    name:<input  name="input1" value="">
    <br>
    <input type="button" value="submit"  class="" onclick="getValue();" > <a  onclick="addTest();"> <font style="cursor:hand;" color="#0033CC">添加商品 </font> </a> <br > 
    <div id="info"> </div>
    </table>
    </form>
    </body>
    </HTML>