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

    Default How to get values for unselected checkbox values

    hello,
    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>
    <th>Name</th>
    <% while(rs.next()){
    %>
    <tr>
    <td>
    <input type="hidden" name="id" value="<%=rs.getString("roll_no") %>"/>
    <input type="checkbox" name="id1" value="<%=rs.getString("roll_no")%>"/></td>
    <td><%=rs.getString("roll_no")%></td>
    <td><%=rs.getString("name")%></td>
    </tr>

    <%}%>
    <input type="submit" value="Mark as absent">
    </form>

    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());
    try
    {
    Class.forName("com.mysql.jdbc.Driver");
    }
    catch(ClassNotFoundException cnfe)
    {
    out.println("<h1>Server Not in Working Stage</h1>");
    }
    try
    {
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=adminsql");
    st=con.createStatement();
    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 06:06 PM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,170
    Rep Power
    20

    Default

    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, 10: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-11-2009, 12:35 AM
  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, 12:55 PM
  4. Replies: 0
    Last Post: 05-22-2008, 11:53 AM
  5. Replies: 4
    Last Post: 04-15-2008, 02: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
  •