Multiple CheckBox Example

Multiple CheckBox Example

Posted in : Java Posted on : June 13, 2011 at 6:10 PM Comments : [ 0 ]

In this section we will discuss about the multiple selectable options.

Multiple CheckBox Example

In this section we will discuss about the multiple selectable options. This example will illustrate you that if any one want to choose multiple options then how it will be possible. The example given below is focusing on such problem. Here we will make multiple checkbox options that one can choose one or more options.


<title>CheckBox Example</title>
<body bgcolor="pink">
<form method="get" action="CheckBox">
<p>Enter your name <input type="text" name="name" /></p>
<h3>Select your hobbies</h3>
<p><input type="checkbox" name="hobbies" value="Gardening" />
<p><input type="checkbox" name="hobbies" value="Playing Game" />
Playing Game</p>
<p><input type="checkbox" name="hobbies" value="Reading Book" />
Reading Book</p>
<p><input type="checkbox" name="hobbies" value="Listening Music" />
Listening Music</p>
<p><input type="checkbox" name="hobbies" value="Jogging" /> Jogging</p>
<p><input type="checkbox" name="hobbies"
value="Chat with net friends" /> Chat with net friends</p>
<p><input type="submit" value="Submit"></input></p>

import javax.servlet.*;
import javax.servlet.http.*;
public class CheckBox extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
String name;
String[] hobbies;
name= req.getParameter("name");
PrintWriter pw = res.getWriter();
hobbies= req.getParameterValues("hobbies");
pw.println("<html><body bgcolor=#00fffff>");
pw.println("Hi I am <h4>"+name+".</h4><br>");
pw.println("My hobby/hobbies are:");
for(int i=0; i<hobbies.length; i++){
pw.println("<p><font color=red>not selected</font></p>");



Output :

When you will run the html file then the following page will display.

When you will select the CheckBoxes and click on submit the following page will display.

If you will not select the any option then the following page will display

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics