document.getElementById("prod_id2_name").count//document.getElementById("prod_id2_name").length

解决方案 »

  1.   

    至少for循环写错了,count如果是标签属性的话没问题。
    <INPUT TYPE="hidden" name="prod_id2_name" count="2">
    <br>prod_cost <INPUT TYPE="text" NAME="prod_cost">
    order_num <INPUT TYPE="text" NAME="order_num">price <INPUT TYPE="text" NAME="price">
    <INPUT TYPE="button" onclick="GetCost()">
    <SCRIPT LANGUAGE="JavaScript"> function GetCost() 
    {
      var mycost=0
    alert(document.getElementById("price").value)
        for (var i=1;i<=document.getElementById("prod_id2_name").count;i++) {      document.getElementById("prod_cost").value = document.getElementById("order_num").value * document.getElementById("price").value
          mycost += new Number(document.getElementById("prod_cost").value);//数字不能用字符串
        }  window.alert(mycost);
    }</SCRIPT>
      

  2.   

    修改成这样了,还是不行,各位大虾继续,我把分数提高到100function GetCost() {
    var mycost;
    mycost = 0;
      for (i=1,i<=document.getElementById("prod_id2_name").length,i++) {
        document.form_order("prod_cost",i).value = document.form_order("order_num",i).value * document.form_order("price",i).value
        mycost += new Number(document.form_order("prod_cost",i).value);   }window.alert(mycost);
    }
      

  3.   

    你把你的html全贴上来 不然没法调试
      

  4.   


     for (i=1;i<=document.getElementById("prod_id2_name").length;i++)//for循环用分号分割
      

  5.   

    function GetCost() {
    var mycost;
    mycost = 0;
      for (i=1,i<=document.getElementById("prod_id2_name").length,i++) {
        document.form_order("prod_cost",i).value = document.form_order("order_num",i).value * document.form_order("price",i).value
        mycost += parseInt(document.form_order("prod_cost",i).value);   }window.alert(mycost);
    }
      

  6.   

    document.getElementById获取的DOM元素节点默认下是无length和count属性的
    楼主请查看是否对其设定了这两个属性做四则运算前,最好是将string强制转换成int或float
    转换方法:parseInt、parseFloat
      

  7.   

    prod_id2_name
    prod_cost
    order_num
    price这几个对象是一组的,动态生成N组对象,每组都共用这组对象名生成文本如下:
    <script language="javascript">
      function add_table () {
      
      var tr = opener.document.createElement("tr"); 
      var td = opener.document.createElement("td"); 
      var tr2 = opener.document.createElement("tr"); 
      var td2 = opener.document.createElement("td"); 
      var tr = opener.document.createElement("tr"); 
      var td = opener.document.createElement("td"); 
      var tbody = opener.document.createElement("tbody"); 
      var table = opener.document.createElement("table"); 
      var mypara = opener.document.getElementById("para");
      var input = opener.document.createElement("input");
      
      mytd = "<p style='line-height: 150%;margin-left: 20;padding: 4px;'>";
      mytd = mytd + "<b>产品编号:</b><%=trim(selrs("prod_id"))%><br>";
      mytd = mytd + "<b>产品名称:</b><%=trim(selrs("prod_name"))%><br>";
      mytd = mytd + "<b>原 产 地:</b><%=trim(selrs("origin"))%><br>";
      mytd = mytd + "<b>产品类型:</b><%=trim(selrs("prod_style_name"))%><br>";
      mytd = mytd + "<b>尺  寸:</b><%=selrs("length")%>cm × <%=selrs("width")%>cm ×<%=selrs("height")%>cm<br>";
      mytd = mytd + "<b>重  量:</b><%=trim(selrs("weight"))%>kg<br>";
      mytd = mytd + "<b>当前库存:</b><%=trim(selrs("sale_store"))%><br>";
      mytd = mytd + "<b>订购数量:</b><input type='text' name='order_num' size='20' value='0' onkeypress='var k=event.keyCode;return k>=48&&k<=57'><br>";
      mytd = mytd + "<b>价  格:</b><%=selrs("price")%><br><input type=hidden id=price name=price_name value='<%=request("price")%>'>";
      mytd = mytd + "<b>活动售价:</b><%=selrs("special_price")%><br><input type=hidden id=special_price name=special_price_name value='<%=request("special_price")%>'>";
      mytd = mytd + "<input type=hidden id=prod_id2 name=prod_id2_name value='<%=request("prod_id")%>'>";
      mytd = mytd + "<input type=hidden id=prod_cost name=prod_cost_name value='0'>";  mytd = mytd + "</p>";
      td.innerHTML = mytd;
      td.setAttribute('class','tmp-td');
      tr.appendChild(td); 
      tr.setAttribute('height','28');
      tr.setAttribute('class','tmp-td');
      
      td2.innerHTML = "<b>&nbsp;订购产品信息</b>";
      td2.bgcolor = '#FF9900';
      td2.setAttribute('bgcolor','#FF9900');
      td2.setAttribute('style','background-color:#C6DEE3');
      tr2.appendChild(td2); 
      tr2.setAttribute('height','28');
      tbody.appendChild(tr2);
      tbody.appendChild(tr);
      table.appendChild(tbody);
      table.setAttribute('width','500');
      mypara.appendChild(table);
      
      input.setAttribute('type','hidden');
      input.setAttribute('id','prod_id');
      input.setAttribute('name','prod_id');
      input.setAttribute('value','<%=request("prod_id")%>');
      mypara.appendChild(input);
      mypara.appendChild(opener.document.createElement("br"));
      mypara.appendChild(opener.document.createElement("br"));  
    };
    add_table();  
    window.close();</script>
      

  8.   

    用分号切割循环条件,还有就是JS没有array.count属性。。貌似PHP里的吧和JS搞混鸟~~
    还有就是 document.getElementById("prod_cost").value = document.getElementById("order_num").value * document.getElementById("price").value
    的写法不好
    效率底下啊,楼主,赋值成变量做吧,多不了几行代码的我们要从开始就养成好的编程习惯。。
      

  9.   

    3楼的代码在ie中可以正确解析,在firefox出错,由于document.getElementById("prod_id2_name"),括号中为name,而不是id