簡體   English   中英

如何識別用戶選擇了哪些?

[英]How can recognize user selected which ones?

我對jsp的請求有兩個清單。 第一個是productGroupName,第二個是products。

現在,我將這些顯示如下。

<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>

如您首先看到的,我迭代productGroupNames,顯示productGroupName下的productID是否等於productGroupID。 但是我在獲取復選框和數量信息時遇到問題。 我需要檢查哪種產品以及需要多少種。

我沒有做Struts,但是他們的文檔至少說您需要<html:multibox>

與其直接進行表單提交,不如通過JS函數提交。 在JS函數中,由於要迭代列表並為復選框和文本字段賦予相同的名稱,因此將獲得具有相同名稱的數組。 那就是您將獲得一個ID數組。 您可以獲取所選復選框的索引,獲取數量,獲取對應的列表元素,並使用該值填充單獨的隱藏表單變量。 然后提交。

一種替代方法是讓每個復選框具有一個隱藏變量,該變量提供列表和復選框之間的某些映射。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM