I have a value set in the request
object like the following,
String[] categoriesList=null; categoriesList = engine.getCategoryNamesArray(); request.setAttribute("categoriesList", categoriesList );
and this is how I iterate in jsp page
<% if(request.getAttribute("categoriesList") != null) { %> <c:forEach var="categoryName" items="${categoriesList}"> <li><a onclick="getCategoryIndex()" href="#">${categoryName}</a></li> </c:forEach> <% }%>
How do I get index of each element and pass it to JavaScript function onclick="getCategoryIndex()"
.
use varStatus to get the index c:forEach varStatus properties
<c:forEach var="categoryName" items="${categoriesList}" varStatus="loop"> <li><a onclick="getCategoryIndex(${loop.index})" href="#">${categoryName}</a></li> </c:forEach>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With