Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Check Box with Jsp:How-To

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey sidh ,
Thnx man...
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic