Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check Box with Jsp:How-To

 
Sanjay Deshpande
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have check boxes whose values r coming from database.
I wanna check which of them are checked on another page.
How ?i m attaching my code. It gives only one cheked value....
----------------------------------
<% while (rs.next()){ %>
<tr bgcolor="LightYellow">
<td width="40"><font color="000000" face="Book Antiqua"> 
<input type="checkbox" name="Check" value="<%=rs.getString("pub_id")%>"> </font></td>
<td><font color="000000" face="Book Antiqua"> 
<%=rs.getString("pub_name")%>
 </font></td>
</tr><%}%>
-----------------------------------
TO CHECK THE ON CHECKBOXES:

String[] p = request.getParameterValues("Check");
while(rs.next())
{

if(rs.getString("pub_id").equals(p[i]))
{
out.println(p[i]+"<br>");

}
}

-----------------------------------------
PLZ LEMME KNOW WHAT'S WRONG?
 
Sid Scud
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the getParameterValues() method returns the values of checkboxes that are checked. So there is absolutely no need to do the following check:
if(rs.getString("pub_id").equals(p[i]))
the array p already contains the values of checked boxes.
Example:
<form action="testCheckbox.jsp">
<input type="checkbox" name="Check" value="1">
<input type="checkbox" name="Check" value="2">
<input type="checkbox" name="Check" value="3">
<input type="checkbox" name="Check" value="4">
<input type="checkbox" name="Check" value="5">
<input type="SUBMIT">
</form>
If this form is submitted by checking first 2 checkboxes... and I do request.getParameterValues("Check"), I will get an array having values 1,2.

-Sid
 
Sanjay Deshpande
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey sidh ,
Thnx man...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic