List of checkboxes
Hi!
I making a list of time-slots with a checkbox against every such time-slot in a JSP page. My requirement is that when one or more checkboxes are checked and the delete button is clicked, then the selected time slots should be deleted. The time slots are getting added in ArrayList but they are not getting removed. The code is=
<center>
<table border="0" width="100%" height="100%" background="images/img1.jpg" style="background-repeat:repeat-x, repeat-y; background-position:top">
<tr>
<td width="10%" height="100%"> </td>
<td width="80%" height="100%">
<table border="0" width="100%" height="100%">
<tr>
<td>
<table border="0" width="100%" height="100%" background="images/header-fill1.jpg" cellspacing="0">
<form action="" name="SchMeetForm">
<tr>
<th colspan="4">
<u>Schedule a Meeting</u>
</th>
<th align="right">
<input type="submit" value="Send" class="but">
</th>
</tr>
<tr align="left">
<td>
Subject:
</td>
<td>
<input type="text" name="subject">
</td>
<td>
</td>
<td>
Where:
</td>
<td>
<select>
<%
MsdsConnection msdsconn;
Statement stmt=null;
ResultSet rs=null;
msdsconn=new MsdsConnection();
msdsconn.initialize(getServletContext());
msdsconn.establishConn();
Connection conn=msdsconn.getMsdsConnection();
stmt=conn.createStatement();
rs = stmt.executeQuery("select loc_name from location");
while(rs.next())
{
%>
<option> <%=rs.getString(1)%> </option>
<% } %>
</select>
</td>
</tr>
<tr align="left">
<td>
Date:
</td>
<td>
<script>DateInput('orderdate', true, 'DD-MON-YYYY')</script>
<!--<input type="button" onClick="alert(this.form.orderdate.value)" value="Show date value passed">-->
</td>
<td>
</td>
<td>
Chair:
</td>
<td>
<select>
<%
rs = stmt.executeQuery("select emp_name from employee");
while(rs.next())
{
%>
<option> <%=rs.getString(1)%> </option>
<% } %>
%>
</select>
</td>
</tr>
</form>
<form action="#" name="TSForm">
<tr align="left">
<td>
When
Starts:
</td>
<td>
<input type="text" name="startsHr" size="1" maxlength="2" OnKeyPress="return validateNumeric()"/>:
<input type="text" name="startsMin" size="1" maxlength="2" OnKeyPress="return validateNumeric()"> [24HH:MM]
</td>
</tr>
<tr align="left">
<td>
Ends:
</td>
<td>
<input type="text" name="endsHr" size="1" maxlength="2" OnKeyPress="return validateNumeric()">:
<input type="text" name="endsMin" size="1" maxlength="2" OnKeyPress="return validateNumeric()"> [24HH:MM]
<input type="submit" name="save" value="Save" class="but" >
</td>
</tr>
</form>
</table>
</td>
</tr>
<%
String btn=request.getParameter("save");
if(btn!=null)
{
%>
<tr>
<td>
<table bgcolor="#F8F8FF" cellspacing="0" border="0" border="0" width="100%" height="100%">
<tr align="center">
<th align="left">
<u> Initiated Time Slots: </u>
</th>
</tr>
<tr align="left">
<td>
<%
String sh=request.getParameter("startsHr");
String sm=request.getParameter("startsMin");
String eh=request.getParameter("endsHr");
String em=request.getParameter("endsMin");
if(sh!=""&&sm!=""&&eh!=""&&em!="")
{
int nsh=Integer.parseInt(sh);
int nsm=Integer.parseInt(sm);
int neh=Integer.parseInt(eh);
int nem=Integer.parseInt(em);
if(nsh<0 || nsh>23 || nsm<0 || nsm>60 || neh<0 || neh>23 || nem<0 || nem>60)
{ %>
Invalid Time!
<% }
else
{
al.add(index);
al.add(sh);
al.add(sm);
al.add(eh);
al.add(em);
index++;
Iterator itr = al.iterator();
while(itr.hasNext())
{
%>
<input type="checkbox" name="ts" value="<%=itr.next()%>">
<%=itr.next()%>:<%=itr.next()%> - <%=itr.next()%>:<%=itr.next()%>
<br>
<%
}
}
String d=request.getParameter("delete");
if(d!=null)
{
String[] p;
p=request.getParameterValues("ts");
if(p!=null)
{
for (int i = 0; i < p.length; i++)
{
int j;
for(j=0;j<al.size();j++)
{
if(al.get(j)==p[i])
break;
}
for(int k=0;k<5;k++)
{
al.remove(j);
}
}
}
}
} %>
</td>
</tr>
<tr align="left">
<td>
<input type="button" value="Remove" class="but" name="delete">
</td>
</tr>
</tr>
</table>
</td>
</tr>
<% } %>
</table>
</td>
<td width="10%" height="100%"> </td>
</tr>
</table>
</center>
View Answers
April 16, 2010 at 5:41 PM
Hi Friend,
We have modified you code, check it:
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<center>
<table border="0" width="100%" height="100%" background="images/img1.jpg" style="background-repeat:repeat-x, repeat-y; background-position:top">
<tr>
<td width="10%" height="100%"> </td>
<td width="80%" height="100%">
<table border="0" width="100%" height="100%">
<tr>
<td>
<table border="0" width="100%" height="100%" background="images/header-fill1.jpg" cellspacing="0">
<form action="" name="SchMeetForm">
<tr>
<th colspan="4">
<u>Schedule a Meeting</u>
</th>
<th align="right">
<input type="submit" value="Send" class="but">
</th>
</tr>
<tr align="left">
<td>
Subject:
</td>
<td>
<input type="text" name="subject">
</td>
<td>
</td>
<td>
Where:
</td>
<td>
<select>
<%
MsdsConnection msdsconn;
Statement stmt=null;
ResultSet rs=null;
msdsconn=new MsdsConnection();
msdsconn.initialize(getServletContext());
msdsconn.establishConn();
Connection conn=msdsconn.getMsdsConnection();
stmt=conn.createStatement();
rs = stmt.executeQuery("select loc_name from location");
while(rs.next())
{
%>
<option> <%=rs.getString(1)%> </option>
<% } %>
</select>
</td>
</tr>
<tr align="left">
<td>
Date:
</td>
<td>
<script>DateInput('orderdate', true, 'DD-MON-YYYY')</script>
<!--<input type="button" onClick="alert(this.form.orderdate.value)" value="Show date value passed">-->
</td>
<td>
</td>
<td>
Chair:
</td>
<td>
<select>
<%
rs = stmt.executeQuery("select name from employee");
while(rs.next())
{
%>
<option> <%=rs.getString(1)%> </option>
<% } %>
%>
</select>
</td>
</tr>
</form>
<form action="#" name="TSForm">
<tr align="left">
<td>
When
Starts:
</td>
<td>
<input type="text" name="startsHr" size="1" maxlength="2" OnKeyPress="return validateNumeric()"/>:
<input type="text" name="startsMin" size="1" maxlength="2" OnKeyPress="return validateNumeric()"> [24HH:MM]
</td>
</tr>
<tr align="left">
<td>
Ends:
</td>
<td>
<input type="text" name="endsHr" size="1" maxlength="2" OnKeyPress="return validateNumeric()">:
<input type="text" name="endsMin" size="1" maxlength="2" OnKeyPress="return validateNumeric()"> [24HH:MM]
April 16, 2010 at 5:42 PM
continue..
<input type="submit" name="save" value="Save" class="but" >
</td>
</tr>
</form>
</table>
</td>
</tr>
<%
String btn=request.getParameter("save");
if(btn!=null)
{
%>
<tr>
<td>
<table bgcolor="#F8F8FF" cellspacing="0" border="0" border="0" width="100%" height="100%">
<tr align="center">
<th align="left">
<u> Initiated Time Slots: </u>
</th>
</tr>
<tr align="left">
<td>
<%
String sh=request.getParameter("startsHr");
String sm=request.getParameter("startsMin");
String eh=request.getParameter("endsHr");
String em=request.getParameter("endsMin");
int index=0;
ArrayList al=new ArrayList();
if(sh!=""&&sm!=""&&eh!=""&&em!="")
{
int nsh=Integer.parseInt(sh);
int nsm=Integer.parseInt(sm);
int neh=Integer.parseInt(eh);
int nem=Integer.parseInt(em);
if(nsh<0 || nsh>23 || nsm<0 || nsm>60 || neh<0 || neh>23 || nem<0 || nem>60)
{ %>
Invalid Time!
<% }
else
{
al.add(index);
al.add(sh);
al.add(sm);
al.add(eh);
al.add(em);
index++;
Iterator itr = al.iterator();
while(itr.hasNext())
{
%>
<input type="checkbox" name="ts" id="ts" value="<%=itr.next()%>">
<label id="div"><%=itr.next()%>:<%=itr.next()%> - <%=itr.next()%>:<%=itr.next()%></label>
<br>
<%
}
}
String d=request.getParameter("delete");
if(d!=null)
{
String[] p;
p=request.getParameterValues("ts");
System.out.println(p);
if(p!=null)
{
for (int i = 0; i < p.length; i++)
{
int j;
for(j=0;j<al.size();j++)
{
if(al.get(j)==p[i])
break;
}
for(int k=0;k<5;k++)
{
al.remove(j);
}
}
}
}
} %>
</td>
</tr>
<tr align="left">
<td>
<input type="button" value="Remove" onclick="del();" class="but" name="delete">
</td>
</tr>
</tr>
</table>
</td>
</tr>
<% } %>
</table>
</td>
<td width="10%" height="100%"> </td>
</tr>
</table>
</center>
<script>
function del(){
if (document.getElementById) {
document.getElementById('ts').style.visibility = 'hidden';
document.getElementById('div').style.visibility = 'hidden';
}
}
</script>
Thanks
Related Tutorials/Questions & Answers:
List of checkboxes - JSP-ServletList of checkboxes Hi!
I making a
list of time-slots with a checkbox against every such time-slot in a JSP page. My requirement is that when one or more
checkboxes are checked and the delete button is clicked
List of checkboxes - JSP-ServletList of checkboxes Hi!
I appreciate your effort for giving the response but now it displays only the last value of ArrayList. In other words, it is now displaying just the last time slot. Also, without clicking the checkbox
Advertisements
The checkboxes tagIn this section, you will learn about
checkboxes tag of Spring form tag library
Array of checkboxes - StrutsArray of checkboxes How to handle unknown number of
checkboxes using tag in an ActionForm. Hi friend,
Code for multiple checkbox
import javax.servlet.http.HttpServletRequest;
import
Updating multiple value depending on checkboxesUpdating multiple value depending on checkboxes Hi .. I want to Update the multiple values of database using
checkboxes and want to set the session for selected
checkboxes..? please answer if any one knows as soon as possible
help me in disabling checked checkboxes modification in this code....such that...
when i select some
checkboxes... remaining
checkboxes as enabled. ADS_TO_REPLACE_2
I have stuck this problem from last
how to get data from checkboxes - JSP-Servlethow to get data from checkboxes hi,
i got
list of tables on screen by invoking webservices.when the user selects the tables by using
checkboxes, i need to get only those tables to the next page where i can get
list of columns
JavaScript Array of checkboxes JavaScript Array of
checkboxes
In this Tutorial we want to describe you a code that help you in
understanding JavaScript Array of
checkboxes. For this we
ListList i do have one
list object, i want to compare this
list from database table and if match found i want to update the
list ListList getting values from a form and make a
list of them and store them into database
list boxslist boxs i have two
list boxes first
list box values from database and i want to assign selected options to the second
list box using jsp is it possible to do this in jsp
Linked listLinked list what is difference btw linked
list in datastructure and linked
list in java
List interfaceList interface Give me some of the real time examples that can be developed based on
List and its implemented classes
Java listJava list What is the difference between a Choice and a
List linked listlinked list Hi i have a problem with linked
list ! how and where i can use linked
list? please give me some example.
Please visit...://www.roseindia.net/java/beginners/linked-
list-demo.shtml
linked list linked
list how to add student and mark and number from file in linked
list and print them also how to make search function plz can help me sooon
linked listlinked list hi i have basal problem what is the linked
list linked listlinked list how to write a program using a linked
list...);
System.out.println("Add elements to LinkedList: ");
LinkedList<String>
list=new...);
}
Collections.reverse(
list);
System.out.println("
List of names in reverse order
list and textboxlist and textbox sir,
i want to create a search, where when i type the letters, the words starting with that letters are to be searched and displayed. Also like a
list i should navigate and select the appropriate word which
Linked List in the following logical linked
list represents Computer Number.
76(head) 98 54...? to ?66?. The segment should also display the new contents of the linked
list.
ii. Write a program segment to copy all ?Dell? computers to a new linked
list linked list program to manage the registration details for the institute.
1. Use a linked
list to manage the details of all registered students.
a. Create your own linked
list Array List Array
List Complete the class House and HouseApp below to display
class House{
int lotNo;
String type; //Bungalow, SemiDetached
double price;
public House ( int l, String t, double p) { � }
public int theLotN() { Ã
DropDown listDropDown list how to get mysql database values into dropdown usign java servlet and ajax?
Here is a jsp code that displays the database values into dropdown
list.
1)country.jsp:
<%@page import="java.sql.*"%>
List In JavaList In Java
In this section we will read about the
List data structure in Java and how
the
List data structure can be implemented in Java.
List data structure is implemented in Java using
List interface.
List
interface allows
pdf list
pdf
list
In this program we are going to know how we can make a
list in a pdf file irrespective... the document by document.open().
Create a numbered
List with 30 point field
List in J2ME
List in J2ME
Exclusive
List MIDlet Example
This example illustrates how to create a Exclusive
List. The Exclusive
List
is used to select only one
list element at a time
List in J2ME List in J2ME
J2ME Canvas
List Example will explain you, how to create
list of items. In
this example we are going to create a simple
list of text, that will show
Merge two list into a single list list. Here you find mainly three function. The insertnode function makes
node... and the
mergelist funtion merge the two lists into a single
list.
Code:
# include... ( struct node *p )
{
printf("The data values in the
list are\n"