Pass integer value from a checkbox on JSP to the server

A

albert kao

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>
 
L

Lew

albert said:
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>

You are telling the checkbox that its value is the string "k".
<td><input type="checkbox" name="choice" value="$k">Data</td>

You are telling the checkbox that its value is the string "$k".
<td><input type="checkbox" name="choice" value=k>Data</td>

You are telling the checkbox that its value is the string "k".
You should get in the habit of enclosing all HTML attribute values in quotes.
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>

You want to use an Expression Language (EL) expression.

<http://www.ibm.com/developerworks/java/library/j-jstl0211.html>
Section on "Variable tags" may be most useful here.

<http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html>
<http://java.sun.com/products/jsp/syntax/2.0/syntaxref207.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top