Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Check Box with Jsp:How-To Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Check Box with Jsp:How-To" Watch "Check Box with Jsp:How-To" New topic
Author

Check Box with Jsp:How-To

Sanjay Deshpande
Ranch Hand

Joined: May 22, 2001
Posts: 111
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

Joined: Mar 13, 2001
Posts: 32
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

Joined: May 22, 2001
Posts: 111
Hey sidh ,
Thnx man...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Check Box with Jsp:How-To
 
Similar Threads
view record from database using click event in jsp
How to check if textboxes are null
problem with java lib
multiple textboxentries .....How-to
Table Allignment problem in IE 6.0