简体   繁体   English

如何识别用户选择了哪些?

[英]How can recognize user selected which ones?

I have two list on my request on jsp. 我对jsp的请求有两个清单。 First one is productGroupName, and the second is products. 第一个是productGroupName,第二个是products。

Now, I show these like below. 现在,我将这些显示如下。

<html:form action="/priceOrder"> <table width="100%" id="tableStyle" style="font: message-box;padding: 20px;">
        <logic:iterate id="productGroups" name="productGroup">
        <tr>
            <td>
            <h3 style="background-color: #720D00; color: white;"><bean:write
                name="productGroups" property="prodGroupName" /></h3>
            <table width="100%" id="tableStyle" style="font: message-box; color: white; padding: 20px; background: #F15A00;">
                <tr>
                    <td width="200px"><strong>Product Name</strong></td>
                    <td width="100px"><strong>How Many</strong></td>
                    <td><strong>Info</strong></td>
                </tr>
                <logic:iterate id="product" name="products">
                <tr>
                    <c:if test="${(productGroups.prodGroupID) == (product.prodGroupID)}">
                        <td>
                            <html:checkbox property="productChecked"  ><bean:write name="product" property="prodName"/></html:checkbox>                                 <br />
                        </td>
                        <td><html:text property="quantity" styleId="check"  size="5"/></td>
                        <td><bean:write name="product" property="prodDesc" /></td>
                    </c:if>
                </tr>
                </logic:iterate>
            </table>
            </td>
        </tr>
    </logic:iterate>

        <tr align="center" style="background-color: #F15A00;"><td height="50px">
              <html:submit styleId="buton" property="method"><bean:message key="button.order" /></html:submit>
        </td></tr>
        <tr><td></td></tr>
    </table></html:form>

As you see firstly I iterate productGroupNames, showing if productID is equal to productGroupID under productGroupName. 如您首先看到的,我迭代productGroupNames,显示productGroupName下的productID是否等于productGroupID。 But I have a problem on getting check box and quantity info. 但是我在获取复选框和数量信息时遇到问题。 I need which product is checked and how many that is wanted. 我需要检查哪种产品以及需要多少种。

我没有做Struts,但是他们的文档至少说您需要<html:multibox>

Instead of doing a form submit directly, submit it through a JS function. 与其直接进行表单提交,不如通过JS函数提交。 In your JS function, since you're iterating your list and giving the checkbox and text field the same name, you'll get an array with the same name. 在JS函数中,由于要迭代列表并为复选框和文本字段赋予相同的名称,因此将获得具有相同名称的数组。 That is you'll get an array of the IDs. 那就是您将获得一个ID数组。 You can get the index of the selected checkbox, get the quantity, get the corresponding list element and populate separate hidden form variables with the value. 您可以获取所选复选框的索引,获取数量,获取对应的列表元素,并使用该值填充单独的隐藏表单变量。 Then submit it. 然后提交。

An alternative approach would be to have a hidden variable associated with each checkbox which provides some mapping between the list and the checkbox. 一种替代方法是让每个复选框具有一个隐藏变量,该变量提供列表和复选框之间的某些映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM