dynamic drop down list box

dynamic drop down list box

View Answers

September 22, 2008 at 12:57 PM



At first u decide, u use servlet ot not, bcoz servlet comes under server side code.

if not using servlet store the all data inside a javascript file.

if u use servlet there might be chance of loss previous displayed data.

for overcome this situation you can use AJAX.

Thanks
Rajanikant

September 22, 2008 at 6:37 PM

Hi friend,

<%@ page language="java" import = "java.util.*;"%>
<%
List userList;
int nouser;
int i=1;
List cityList;
int nocity;
int j=1;
%>
<%
userList=(ArrayList)request.getAttribute("useridList");
nouser = userList.size();
%>

<%
cityList=(ArrayList)request.getAttribute("cityList");
nocity=cityList.size();
%>
<html>
<head>
<title>dynamic bombobox in servlet</title>
</head>
<body>
<br><br>
<center>
<table border="1" width="300px" bgcolor="bluelight" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<form method="GET" action="/examples/jsp/ComboboxList">
<font color="red"><h3 align="center">Dynamic Combobox List</font></h3>
<table border="1" width="300px" cellspacing="0" cellpadding="0">
<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><select name="userid" value="">
<option value="0">---Select Name---</option>
<%
Iterator userit= userList.iterator();
while(userit.hasNext()){
while(i<=nouser){%>
<option value="<%=i%>"><%=userit.next()%></option>
<%
i++;
}
}
%>
</select>
</td>
</tr>
<tr>
<td width="50%"><b>City:</b></td>
<td width="50%">
<select name="city" value="">
<option value="0">----Select city----</option>
<%
Iterator cityit= cityList.iterator();
while(cityit.hasNext()){
while(j<=nocity){%>
<option value="<%=j%>"><%=cityit.next()%></option>
<%
j++;
}
}
%>

</select>

</td>
</tr>

</table>

</form>
</td>
</tr>
</table>
</center>
</body>

</html>

September 22, 2008 at 6:38 PM

servlets code

package javacode;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import java.util.ArrayList;

public class ComboboxList extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from Combolist");
List ulist = new ArrayList();
List clist = new ArrayList();
while(rs.next()){
request.setAttribute("userid", rs.getString(2));
request.setAttribute("city", rs.getString(3));
pw.println("userid" + " "+"city"+"<br>");
pw.println(rs.getString(2) + " " + rs.getString(3) +"<br>");
ulist.add(rs.getString(2));
clist.add(rs.getString(3));

}
request.setAttribute("useridList", ulist);
request.setAttribute("cityList", clist);
}
catch (Exception e){
pw.println(e);
}
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/Combobox.jsp");
dispatcher.forward(request, response);
}

}


September 22, 2008 at 6:40 PM

web.xml

<servlet>
<servlet-name>comboboxList</servlet-name>
<servlet-class>javacode.ComboboxList</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>comboboxList</servlet-name>
<url-pattern>/jsp/ComboboxList</url-pattern>
</servlet-mapping>


--------------------------------------

Read for more information.

http://www.roseindia.net/servlets/

Thanks.

Amardeep.









Related Tutorials/Questions & Answers:
dynamic drop down list box - Java Beginners
dynamic drop down list box  hi all , I want to dynamically populate a drop down box from an sql query in a servlet program, using only html... Dynamic Combobox List
dynamic drop down list
dynamic drop down list  I want to create 2 drop down list, where it takes value from database and the two list are dependent..means if I select a particular value from one the other list is developed accordingly..depending
Advertisements
Dependant & dynamic drop down list
Dependant & dynamic drop down list  I don't know this should be in this or AJAX forum. I have one dynamic drop down list from data base (working... on the values selected by user in first drop down list. How to achieve this ?   
store values of drop down list box in database
store values of drop down list box in database  how to store values of drop down list box in oracle database in jsp?I have information inserting form where i have date of birth as drop down list box
Dependant & dynamic drop down list - Follow up
Dependant & dynamic drop down list - Follow up  Thanks for your answer. As per your answer This will select only ONE row (country) from first drop down. In my case user can choose more than one row , which is then sent to next
retrive the data from access database to drop down list box in jsp
retrive the data from access database to drop down list box in jsp  hai, im new to jsp now im using the jsp along with access database.in table i load all the data's i need to retrive the data from database to dropdown list box
Drop Down Box
Drop Down Box  In a Drop Down box I want to show the user All the Country In the World. And when he type A-z,then each of the type Show those country which start with those word. Like I For-India
dynamic drop down
dynamic drop down   I have created 2 drop downs in jsp.1 for department and other for its related designation.that means if I select a department... into the designation drop down (use jsp+javascript+servlet) reply soon   1
drop down box - JSP-Servlet
drop down box  when i enter some letter in the input box,the corresponding words of that particular letter must be displayed below as a list from the data base in the same input box as drop down. Thanks&Regards, VijayaBabu.M
drop down list in Struts
drop down list in Struts  How to create a drop down list in Struts
validation for drop down list
validation for drop down list  Hi all I have a form, it contain 12 drop down list. Each drop down has 1 to 5 values,i need to validate this form. the following condition should be true. 1.you can choose only 3 times 5 value. 2
dynamic creation of multiple drop-down menus
dynamic creation of multiple drop-down menus  can anybody plz help me in coding for dynamic creation of multiple drop-down menus in a webpage using ajax/js/html/css
Dependent drop down list
dependent drop down list is used my code is successful but when i select class from first drop down list all the data get lossed means the value entered in fields before drop down list get blank.what can i do for this? This is the code
Get values in drop down list
Get values in drop down list  Pls provide me jsp code to get values in drop down list from another table's field. my project has customer... in drop down box in front end..... pls provide me code.. thanx
Drop down list from database
Drop down list from database  Hi, Can I know how do we get the drop down list from database? Eg: select country--select state--select district--so on.   1)country.jsp: <%@page import="java.sql.*"%> <html>
dependent drop down box - JSP-Servlet
dependent drop down box  haloo sir Please give me the solution how to extract data from dependent drop down box with page refresh, If possible please give some example for better understanding
Select functionality of drop down list - Struts
have Drop down list having element Test1,Test2,Test3,HIDE and one Text msg box for entering Age,Now if user select "HIDE" from drop-down list the below text...(in struts application) in which if user select HIDE from the drop down list
how to import values from database to the drop down box
how to import values from database to the drop down box   hi iam... employee page i kept a drop down box for employee Ids i want all employee IDs will display in the drop down box please help me with the code
Display related data in other drop down list on selecting one data in one drop down list
Display related data in other drop down list on selecting one data in one drop down list  How to display related datas in dropdown list from database on selecting one data in previous dropdownlist in Java Server Page
jsp login code ... when username , drop down box and password is correct
jsp login code ... when username , drop down box and password is correct  i need a jsp code for login.... when username password and dropdown box value is correct.... the drop down box values should be retrieved from database
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
Excel Cell Drop Down List
Excel Cell Drop Down List In this section, you will learn how to validate data entered in a cell and provide a drop down list of possible values to the user... in a excel sheet's cell and also can provide drop list of possible value
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...(); List officenames = new ArrayList(); DropDownChoice officename = new
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...(); List officenames = new ArrayList(); DropDownChoice officename = new
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...(); List officenames = new ArrayList(); DropDownChoice officename = new
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...(); List officenames = new ArrayList(); DropDownChoice officename = new
view data from database using drop down list
view data from database using drop down list  hi i want to view the data from database by selecting a value in a drop down list. for an example drop down list have picture element.when click it select pictures from the database
Drop Box
Drop Box  program draw 2d shapes in java
Drop Box
Drop Box  program draw 2d shapes in java
Dynamic loading of Combo box list using servlet - JSP-Servlet
Dynamic loading of Combo box list using servlet  I have the category... I give theortical descrption read it! Select a value from drop dwon box... Dynamic Combobox List User
Dynamic Dropdown Menu
records from your database in a drop down menu/list box. You can apply it as a navigator list box. Good for saving your webpage areas or you have many links you..._TO_REPLACE_5 <title>Dynamic Drop Down List</title> </head> <
how to retreive data dynamically from mysql to drop down list
how to retreive data dynamically from mysql to drop down list   sir, i created a table in mysql and i inserted some values into the table through... the data of a particular column in a table into drop down list dynamically
How to create a dependent drop down list using [Apache POI]
How to create a dependent drop down list using [Apache POI]  Here I.... In that two drop down list are there. Want to create a drop down list that depends..., and "rice, curd, milk" items will appear in the dependent drop down list in cell
How to create a dependent drop down list using [Apache POI]
How to create a dependent drop down list using [Apache POI]  Here I.... In that two drop down list are there. Want to create a drop down list that depends..., and "rice, curd, milk" items will appear in the dependent drop down list in cell
drop down
drop down  how can i add data from choice/dropdown component of java awt to myaql table
Drop Down
Drop Down  How to insert date into database using dropdown like facebook
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...)&& ($select!="")){ $select=$_POST['NEW']; } ?> <?php $list
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...)&& ($select!="")){ $select=$_POST['NEW']; } ?> <?php $list
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...)&& ($select!="")){ $select=$_POST['NEW']; } ?> <?php $list
drop down list doPost() servlet - Servlet Interview Questions
drop down list doPost() servlet  Can someone assist me HOW to invoke drop down menu list in doPost() servlet? Upon selecting and clicking a submit button, the doPost will be invoked, and will appear. Let say we have this code
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
how to set a value of dynamic number of drop down lists on a jsp page and access it value on another jsp page
how to set a value of dynamic number of drop down lists on a jsp page... page pe v r creating these dynamic number of drop down lists having name rating1 ,rating2......number of buks in that category(and each drop down list has value
The code for retrieving data from database into Drop Down List.
The code for retrieving data from database into Drop Down List.  <% DataSource data = new MysqlDataSource(); Connection con...; Book List : - select - <% while
Drop Down reload in IE
Drop Down reload in IE  Hi i was using two drop down box..One for Displaying date followed by another for Dispalying Month..If i Select/Change Month from the 2nd drop down then the 1st drop down ( which is date) automatically
Pls provide me jsp code to get values in drop down list from another table's field....
Pls provide me jsp code to get values in drop down list from another table's field....  my project has customer registration and company registration... in customer registration page and should be shown in drop down box in front end
drop down menu
drop down menu  drop down menu using html
Login With Drop Down
box and then login to the page. I have a drop down list box with Customs... a drop down list consisting of Customs and Accounts. I have user accounts of both... by selecting the drop down box. Suppose the Customs username is 1001 and Accounts
How to pass parameter through drop down list using session management in jsp??
How to pass parameter through drop down list using session management in jsp??  How to pass parameter through drop down list in the URL and access it on same jsp page using session management
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database
Drop down menu
Drop down menu  I have drop down list of some 14 links which links to the table,If i click each link the table should display below the link and again if i click the link the table should not appear. please help me

Ads