我在表单中有一个隐藏字段,其值由javascript设置。我已确认该值确实已设定。但是,当我尝试将其发送到servlet时,它会生成一个空值。我使用POST方法提交给servlet并使用" submit"按钮。该值是通过" 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>
答案 0 :(得分:0)
您的foreach语句(标记)与表单标记重叠。
您需要具有以下格式:
<c:forEach ...> <form ...> ... </form> </c:forEach>
答案 1 :(得分: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>