Read Form Checkboxes : Form CheckBox « JSP « Java Tutorial






index.jsp

<HTML>
    <HEAD>
        <TITLE>Submitting Check Boxes</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Submitting Check Boxes</H1>
        <FORM ACTION="basic.jsp" METHOD="post">
             <INPUT TYPE="CHECKBOX" NAME="check1" VALUE="check1" CHECKED>
             Checkbox 1
            <BR>
            <INPUT TYPE="CHECKBOX" NAME="check2" VALUE="check2">
            Checkbox 2
            <BR>
            <INPUT TYPE="CHECKBOX" NAME="check3" VALUE="check3">
            Checkbox 3
            <BR>
            <INPUT TYPE="SUBMIT" VALUE="Submit">
        </FORM>
    </BODY>
</HTML>

basic.jsp

<HTML>
    <HEAD>
        <TITLE>Reading Checkboxes</TITLE>
    </HEAD>

    <BODY>
        <H1>Reading Checkboxes</H1>
        <%
            if(request.getParameter("check1") != null) {
                out.println("Checkbox 1 was checked.<BR>");
            }
            else {
                out.println("Checkbox 1 was not checked.<BR>");
            }

            if(request.getParameter("check2") != null) {
                out.println("Checkbox 2 was checked.<BR>");
            }
            else {
                out.println("Checkbox 2 was not checked.<BR>");
            }

            if(request.getParameter("check3") != null) {
                out.println("Checkbox 3 was checked.<BR>");
            }
            else {
                out.println("Checkbox 3 was not checked.<BR>");
            }
        %>
    </BODY>
</HTML>
  Download:  ReadFormCheckboxes.zip( 1 k)








23.17.Form CheckBox
23.17.1.Check the CheckBox in your code based on the selection on RadioButton
23.17.2.Read Form Checkboxes