javascript - Display only four elements in a row in table using jsp -


i generating checkboxes in row dynamically want display 4 checkboxes in row , in next row. tried code couldn't achieve goal. please me out

<c:foreach var="group" items="${actionbean.roles}" varstatus="loop">         <table>          <tr>           <td><s:checkbox name="category1" id="category${loop.index}" class="category"             onclick="onchangecheckbox(this,id)" checked="false"></s:checkbox> <b> <s:label for="${group}" />           </b></td>          </tr>          <tr>           <c:foreach var="item" items="${actionbean.activityroles}">             <c:if test="${not empty actionbean.activityroles && item.label == group }">               <td width="25%"><s:checkbox name="category11" value="${item.id}" class="category${loop.index}"></s:checkbox> <s:label                 for="${item.name}" title="${item.description}" /></td>            </c:if>           </c:foreach>          </tr>         </table>        </c:foreach> 

in code have checkbox heading , child checkboxes in next row. dynamically generated.

<script> function onchangecheckbox(checkbox, checkid) {         if (checkbox.checked) {           $('.' + checkid).attr('checked', true);         } else {           $('.' + checkid).attr('checked', false);         }       } </script> 

you can use variable check whether item 4 , break like. didn't test code below (it may have syntax error) should around that, hope help:

<c:foreach var="group" items="${actionbean.roles}" varstatus="loop">     <table>         <tr>             <td colspan="4"><s:checkbox name="category1" id="category${loop.index}" class="category"                 onclick="onchangecheckbox(this,id)" checked="false"></s:checkbox> <b> <s:label for="${group}" />                 </b>             </td>         </tr>         <c:set var="index" value="0"/>         <c:foreach var="item" items="${actionbean.activityroles}" varstatus="s">             <c:if test="${index % 4 eq 0}">                 <tr>             </c:if>             <c:if test="${not empty actionbean.activityroles && item.label == group }">                 <td width="25%">                     <s:checkbox name="category11" value="${item.id}" class="category${loop.index}"></s:checkbox>                     <s:label for="${item.name}" title="${item.description}" />                 </td>                 <c:set var="index">${index + 1}</c:set>                 <c:if test="${s.last && index % 4 neq 0}">                     <td colspan="${4 - (index % 4)}">&nbsp;</td>                 </c:if>             </c:if>             <c:if test="${index % 4 eq 3 || s.last}">                 </tr>             </c:if>         </c:foreach>     </table> </c:foreach> 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -