SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pass integer value from a checkbox on JSP to the server

    How to pass integer value from a checkbox on JSP to the server?
    None of the following 3 checkboxes will pass an integer to the server.
    The server receive "k" or "$k" but not 1, 2, 3, ....
    <td><input type="checkbox" name="choice" value="k">Data</td>
    <td><input type="checkbox" name="choice" value="$k">Data</td>
    <td><input type="checkbox" name="choice" value=k>Data</td>

    The JSP page is:
    <c:set var="k" value="0"/>
    <c:forEach items="${model.data}" var="data">
    <tr>
    <c:forEach items="${data}" var="datavalue">
    <td style="font-family:monospace">${datavalue}</td>
    </c:forEach>
    <td><input type="checkbox" name="choice" value="k">Data</td>
    <c:set var="k" value="$(k+1)"/>
    </tr>
    </c:forEach>

  2. #2
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in this line:
    <td><input type="checkbox" name="choice" value="k">Data</td>

    Your value="k" should be value="${k}"

    But instead of using a variable, the forEach has a built in counter. You can do

    <c:forEach items="${model.data}" var="data" varStatus="status">
    <c:out value="${status.count}"/>
    </c:forEach>

    Where status.count will be the loop count. Status has some other properties but I forget what they are.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •