Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet List of checkboxes
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Khushbu Arora
List of checkboxes
2 Answer(s)      4 years and 6 months ago
Posted in : JSP-Servlet


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>

Advertisement
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


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
List of checkboxes - JSP-Servlet
List 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 tag
In this section, you will learn about checkboxes tag of Spring form tag library
checkboxes set to true using JavaScript
checkboxes set to true using JavaScript  To set all checkboxes to true using JavaScript
Array of checkboxes - Struts
Array 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 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
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
Jsp-delete checked checkboxes and display UNCHECKED checkboxes in table as well as in store that unchecked checkboxes in ARRAYLIST
Jsp-delete checked checkboxes and display UNCHECKED checkboxes in table as well as in store that unchecked checkboxes in ARRAYLIST  I have a table... checkboxes should be displayed. And we should keep remaining checkboxes
List
List  getting values from a form and make a list of them and store them into database
how to get data from checkboxes - JSP-Servlet
how 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
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
help me in disabling checked checkboxes
in this code....such that... when i select some checkboxes and submit this form..., it should display previoue checked checkboxs as disabled.and remaining checkboxes
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
dropdown wth checkboxes - Design concepts & design patterns
dropdown wth checkboxes  Hi Friends, Instead of using Ctrl key i want to put checkboxes inside the dropdown,then we can check the options whatever we want. Please give me the html code(only html & javascript). Thanks
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
Remove checked checkboxes from arraylist and dipaly remaining arraylist
Remove checked checkboxes from arraylist and dipaly remaining arraylist  I want to delete checked checkboxes after submitting button. And i want... elements). For , this problem i tried to get all checked checkboxes names in string
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
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
List interface
List interface  What is the List interface
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
linked list
linked list  program for single linked list
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
List interface
List interface  Give me some of the real time examples that can be developed based on List and its implemented classes
Linked list
Linked list  what is difference btw linked list in datastructure and linked list in java
List of mobiles
List of mobiles  which mobile phones support j2me
Java list
Java list  What is the difference between a Choice and a List
After changing url params d req checkboxes are not showing as clicked in jsf programming - Java Server Faces Questions
After changing url params d req checkboxes are not showing as clicked in jsf... richfaces) There is having a list of artist . If u click on a particular artistname then the respective albums(with their checkboxes) will show up like
 

 

 

DMCA.com