开发者

JSP and HTML - Naming check boxes with different names from a loop

I have something like this in my code

开发者_开发知识库
<% while (i.hasNext()) {
     Object obj = i.next();
        ...
%>
        ...
     <input type="checkbox" name="ticketCheck"/>
        ...

<% } %>

How can I make the names become ticketCheck1, ticketCheck2 etc so I can reference a corresponding object that displays?


assuming tickets is the collection or array of ticket

      <c:forEach var="ticket" items="${tickets}">
        <TR>
           <input type="checkbox" name="${ticket}"/>
        </TR>
      </c:forEach>


Here is a different example. This assumes that tickets is a list of objects and that for each object there is defined a getValue() and getName() method.


<c:forEach var="item" items="${tickets}">
...
...
<input type="checkbox" value="${item.value}" name="${item.name}"/>
...
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜