0

我在表单中有一个隐藏字段,其值由 javascript 设置。我已经确认该值确实已设置。但是,当我尝试将其发送到 servlet 时,它会产生一个空值。我确实使用 POST 方法和“提交”按钮提交给 servlet。该值是通过用户在“qtyText”文本框中输入获得的。在 JS 中,它的值是动态设置的。为什么它不会被发送到 servlet?JS

   function(calculateTotalPrice(txtbxvalue, price)
  {
   myForm = document.forms[0];        
      var txtBx = myForm.elements['qtyText'];
      var txtBxHidden = myForm.elements['qtyTextHidden'];
      for(var i = 0; i < txtBx.length; i++) 
         {
          var curTxtBx = txtBx[i].value; 
          var txtBxHiddenBx = txtBxHidden[i];
           txtBxHiddenBx.value = curTxtBx;
         }
   }

HTML

<table>

   <c:forEach items="${ListInServlet}" var= "exBean">
  <form name = "tableForm" method = "post" action= "/rpsapp/someservlet">
    <input type="hidden" name="productId" value= "<c:out Value 
                                          = "${exBean.productId}"/>"  />
         <input type="hidden"  value = "somevalue" name="qtyTextHidden"/>
         <input name = "qtyText" type = "textbox" size = "2" value = "" onChange 
                              = "calculateTotalPrice(this, '${exBean.price}')"/>

   </c:forEach>
  </form>
</table>
4

2 回答 2

0

您的 foreach 语句(标签)与表单标签重叠。

您需要具有以下格式:

<c:forEach ...> <form ...> ... </form> </c:forEach>
于 2013-03-09T14:37:22.637 回答
0

您必须创建与产品一样多的隐藏变量。

  <form name = "tableForm" method = "post" action= "/rpsapp/someservlet">
   <c:forEach items="${ListInServlet}" var= "exBean">
    <input type="hidden" name="productId${exBean.productId}" value= "<c:out Value 
                                          = "${exBean.productId}"/>"  />
         <input type="hidden"  value = "somevalue" name="qtyTextHidden${exBean.productId}"/>
         <input name = "qtyText${exBean.productId}" type = "textbox" size = "2" value = "" onChange 
                              = "calculateTotalPrice(this, '${exBean.price}')"/>

   </c:forEach>
  </form>
于 2013-03-09T19:42:59.377 回答