Results 1 to 2 of 2
  1. #1
    sarath13 is offline Member
    Join Date
    Jan 2011
    Rep Power

    Default How to get values for unselected checkbox values

    the below code is the jsp page for attendance ,that fetches two columns from database(mysql),reg no and name and it has a checkbox column. If the student is absent,the corresponding check box is selected and it is submitted to the another jsp page which marks attendance present for unselected checkbox values and absent for selected checkbox in the database.

    <form name="form1" method="POST" action="attn1.jsp" onSubmit='return valid(this)' >

    <table border=2>
    <tr><th> </th>
    <th>Roll no</th>
    <% while({
    <input type="hidden" name="id" value="<%=rs.getString("roll_no") %>"/>
    <input type="checkbox" name="id1" value="<%=rs.getString("roll_no")%>"/></td>

    <input type="submit" value="Mark as absent">

    here the problem is after submitting, i got the result as absent for selected checkboxes and present for both selected and unselected checkboxes.But i want present only for unselected checkboxes.Eventhough i used hidden input field,but it cannot solve it..
    please help.....

    here is the code for next jsp page(attn1.jsp)
    String select[] =request.getParameterValues("id");
    String[] chkboxvalues=request.getParameterValues("id");
    SimpleDateFormat test = new SimpleDateFormat("dd / MM / yyyy");
    Calendar cal = Calendar.getInstance();
    String date=test.format(cal.getTime());
    catch(ClassNotFoundException cnfe)
    out.println("<h1>Server Not in Working Stage</h1>");
    if (select != null && select.length != 0) {
    for (i = 0; i < select.length; i++) {
    st.executeUpdate( "insert into testattn(roll_no,attendance,date) values('"+select[i]+"','"+abs+"','"+date+"')");

    if (chkboxvalues != null && chkboxvalues.length != 0) {
    for (i = 0; i < chkboxvalues.length; i++) {

    st.executeUpdate( "insert into testattn(roll_no,attendance,date) values('"+chkboxvalues[i]+"','"+pres+"','"+date+"')");

    Last edited by sarath13; 01-06-2011 at 05:06 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    Java Code:
    String select[] =request.getParameterValues("id");
    String[] chkboxvalues=request.getParameterValues("id");
    Both of these are getting the hidden id field.
    You're not looking at the checkbox at all.

    Also (and this maybe simply how you're being taught), but that code for processing should be in a Servlet, or preferably in its own layer called from a Servlet. JSPs are for displaying data, not for processing.

Similar Threads

  1. Replies: 3
    Last Post: 07-27-2010, 09:52 AM
  2. HashMap contains all values but doesn't show all values
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 05-10-2009, 11:35 PM
  3. passing object as value for checkbox values??
    By Pooja Deshpande in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-17-2009, 11:55 AM
  4. Replies: 0
    Last Post: 05-22-2008, 10:53 AM
  5. Replies: 4
    Last Post: 04-15-2008, 01:04 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts