Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Check Box with Jsp:How-To

 
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?
 
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!