Hello guys this may be easy question but I m finding it quite tricky.
Scenario is I m printing all the values from the database table using jstl foreach.

            <c:forEach items="${pal}" var="p">
            <tr>
            <td><c:out value="${p.pid}"></c:out></td>
            <td><c:out value="${p.pname}"></c:out></td>
            <td><c:out value="${p.pdesc}"></c:out></td>
            <td><c:out value="${p.pestd}"></c:out></td>
            <td><a id="popa" href="#">Allocate</a></td>
            </tr>
            </c:forEach>

And now onclick Allocate button I want that particular pid (i.e suppose there are 1,2,3,...,10 pid so when I click on 4th I should get the 4th pid as a value) in jquery.

But in jQuery when I try to get that value I always got last value in the loop whichever button I click.

Please Help me and guide me how to get the current value of pid on click in jQuery.

I hope this helps :

<c:forEach items="${pal}" var="p">
            <tr>
            <td><c:out value="${p.pid}"></c:out></td>
            <td><c:out value="${p.pname}"></c:out></td>
            <td><c:out value="${p.pdesc}"></c:out></td>
            <td><c:out value="${p.pestd}"></c:out></td>
            <td><a id="popa" href="#" onClick="myFunc(${p.pid})">Allocate</a></td>
            </tr>
            </c:forEach>

            <script>
                function myFunc(pId) {
                    //do whatever you want to do with pid

                    return false;
                }
            </script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.