List of checkboxes

Ads
 

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%">&nbsp;</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>
&nbsp;
</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>
&nbsp;
</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 &nbsp;&nbsp;
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()"> &nbsp; [24HH:MM]
</td>
</tr>
<tr align="left">
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
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()"> &nbsp; [24HH:MM] &nbsp;
<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()%>&nbsp;-&nbsp;<%=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%">&nbsp;</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%">&nbsp;</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>
&nbsp;
</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>
&nbsp;
</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 &nbsp;&nbsp;
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()"> &nbsp; [24HH:MM]
</td>
</tr>
<tr align="left">
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
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()"> &nbsp; [24HH:MM] &nbsp;

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()%>&nbsp;-&nbsp;<%=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%">&nbsp;</td>
</tr>
</table>
</center>
<script>
function del(){

if (document.getElementById) {
document.getElementById('ts').style.visibility = 'hidden';
document.getElementById('div').style.visibility = 'hidden';
}
}
</script>

Thanks

Ads









Related Tutorials/Questions & Answers:
List of checkboxes - JSP-Servlet
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
The checkboxes tag
In this section, you will learn about checkboxes tag of Spring form tag library
Advertisements
Updating multiple value depending on checkboxes
Updating 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
Maintaining States of Selected CheckBoxes in Different Pages using dispaly table in struts2
Maintaining States of Selected CheckBoxes in Different Pages using dispaly... i am showing the list using a displaytag.Each row in the list has a checkbox. Actually my requirement is to select particular checkboxes across different pages
Retriving multiple values of checkboxes in struts
Retriving multiple values of checkboxes in struts  how to retrive multiple values of checkboxes of jsp in action class   JSP Retrieve checkbox values 1)checkbox.jsp: <html> <body> <form method="post
how to display selected checkboxes dynamically using jsp
how to display selected checkboxes dynamically using jsp  Hi friends i have a requirement that : in my JSP page i have radio buttons followed by the DB fields..when i click SUBMIT button,if the field(or record
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
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
How to add a column with checkboxes for each record in my table in JSP
How to add a column with checkboxes for each record in my table in JSP   Hi, Could you please explain it to me how I can add a column with check boxes for each record in my table in JSP? Also, I want to figure out a way
want to ask how to update data for runtime selected multiple checkboxes
have checkboxes for each record when I will select more than one checkboxex...;H3>LIST OF CUSTOMERS-ADDRESS TO BE CONFIRMED</H3> <input type
how to update combobx's selected value to database with respect toselected multiple checkboxes
how to update combobx's selected value to database with respect toselected multiple checkboxes   suppose this if form1.jsp in which i am going to display records from database out.println("<tr><td>"+"<input type
List
List  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
List
List  getting values from a form and make a list of them and store them into database
Delete multiple records with pagination by selecting checkboxes
ModuleNotFoundError: No module named 'list-in-list'
ModuleNotFoundError: No module named 'list-in-list'  Hi, My Python... 'list-in-list' How to remove the ModuleNotFoundError: No module named 'list-in-list' error? Thanks   Hi, In your python
list boxs
list 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 list
linked list  program for single linked list
Linked list
Linked list  what is difference btw linked list in datastructure and linked list in java
List interface
List interface  Give me some of the real time examples that can be developed based on List and its implemented classes
List of mobiles
List of mobiles  which mobile phones support j2me
linked list
linked 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 list
linked list  hi i have basal problem what is the linked list
linked list
linked 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
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
List In Java
List 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
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 list
DropDown 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.*"%>

Ads