B.PREM KUMAR
List Box
1 Answer(s)      4 years ago
Posted in : JSP-Servlet

View Answers

June 12, 2009 at 4:51 PM


Hi Friend,

To run this code we have created two tables country(id,country_name) and city(cityId, id,city_name). Now when we select the country from the first
combobox it will fetch the name of the cities according to the country Id.
Here is the JSP page code as follows :

<%@ page language="java" %>
<%@ page import="java.sql.*" %>

<%!
Connection conn = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "mysql";
String user = "root";
String pass = "root";
ResultSet rs =null;
Statement st=null;
String query="";
int mid;
%>
<%
if(request.getParameter("mid")!=null){
mid=Integer.parseInt(request.getParameter("mid"));
}else {
mid=0;
}
Class.forName("com.mysql.jdbc.Driver") ;
conn = DriverManager.getConnection(url+db, user, pass);
st = conn.createStatement();
rs = st.executeQuery("select * from country");
%>
<html>
<head>
<script type="text/javascript">

function selectCity(){
var mid=document.getElementById("countryId").selectedIndex;
window.location.replace("http://localhost:8080/examples/jsp/newCombo.jsp?mid="+mid);
}

</script>
</head>
<body>
<select id="countryId" name="countryId" onchange="selectCity(this)">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value='<%=rs.getString("id")%>'><%=rs.getString("country_name")%></option>
<%}%>
</select>
<select>
<option value="0">--Please Select--</option>
<%
System.out.println(mid);
rs = st.executeQuery("select * from city where id='"+mid+"'");
while(rs.next()){ %>
<option value='<%=rs.getString("id")%>'><%=rs.getString("city_name")%></option>

<%}%>
</select>

</body>
</html>

Thanks









Related Pages:
List Box - JSP-Servlet
list box.on selecting one value in list box,i will retrieve values from database and store into another list box in same page using javascript :location.my problem is in first list box,value which i selected to get values is not displaying
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using method ? Please give me the code snipetts
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using method ? Please give me the code snipetts
Javascript List Box - JSP-Servlet
itself.my problem is in list box the semester which i selected is not showing in list box as selected.when i select,the page refreshes but i get the result what i expected.i need to show in list box as semester is selected but it doesnt
jsp list box - Java Beginners
jsp list box  I have two list boxs. the values for the first list box is retrieved from the mysql database. I want to fill the second list box selected item from the database. Please help me in this regard. Your help
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using... ListSelectionListener { private JList list; private DefaultListModel listModel..."); //Create the list and put it in a scroll pane. list = new
PHP list box mysql
PHP List box that displays the data from mysql table. User can select any value from the PHP list box. Example of PHP MYSQL List Box Code <?php if(isset($_GET['roll'])) { $username="root"; $password=""; $database
PHP List Box Post
The PHP Post List box is used in the form. It contains multiple value User can select one or more values from the PHP list Box This PHP Post List Box is the alternate of Combo box PHP Post List Box Example <?php
PHP list box
The PHP List box is used in the form. It takes input values from the user. The PHP List box contains multiple values at a time. PHP List Box Example <?php      if(isset($_GET['hobbie']))   
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
scroll bars to list box - JSP-Servlet
scroll bars to list box  Can I add scroll bars to a list box in struts?  Hi friend, Scroll the list box in struts Two attribute set "multiple" "size". Select Tag Example Select Tag
Passing Multi select list box values using ajax to get values to dependent list box
Passing Multi select list box values using ajax to get values to dependent list box  Hi, I have a jsp page which has 3 dependent list boxes... the dependent values to the immediate next list box. Please help me
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
List the names of classes used to create button and text box in Java.
List the names of classes used to create button and text box in Java.  List the names of classes used to create button and text box in Java
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
combo box
combo box  Hi, [_|] dropdown box...] | | | LEFT LIST | | RIGHT LIST... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get
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
remove item from list box using java script - Java Beginners
remove item from list box using java script  remove item from list box using java script  Hi friend, Code to remove list box item using java script : Add or Remove Options in Javascript function addItem
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
dialog box
) { ArrayList<ArrayExample> list=new ArrayList<...:")); for(ArrayExample e:list){ if(e.getIde()==inputID
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  Hi, how to dynamically increase size of list... insert new course in a table.. It should be seen in my list box
input type dialog box take text and search a list and focus that text - JSP-Servlet
input type dialog box take text and search a list and focus that text  i have a button..when i press it will prompt a dialog box with a text box... then it will search a list which contains data in the same page and if found
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
dropdown list in jsf
dropdown list in jsf  I want to add a list box to display the country name from the lists on all countries.When I select for e.g India then in the second list box it will display the states related to India only and the flow
enable text box and label on selection
enable text box and label on selection  hello, Please tell me how to enable label and text box on selection of drop down list box. in drop down list box all values come from database. please reply
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only... added select box also into next jsp page plz reply me as early as posssible
populating the combo box - Struts
the combo box with a table in MS SQL Server 2005 Management Studio Express. Belo...) { ArrayList list = new ArrayList(); try { connectToDb(); // String sec = null... { closeConnection(); } return list; } public ArrayList getCompanyBySector
Helps with combo box and frame
Helps with combo box and frame  Hi i have a combobox and when i click... on the second window and click confirm i would have the information on the combo box. i... = new JFrame("Add-Remove item to list"); String items
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
displaying data for a single column from Mysql database in the list box in php form
displaying data for a single column from Mysql database in the list box in php form  I have a form in php.want to display data from a single column in an listbox in php.thanks..   <?php $data = @mysql_query("select
Dojo Combo Box
or list box and a single-line textbox, allowing the user either to type a value...Dojo Combo Box          In this section, you will learn what is combo box and how to create
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
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
how to operate on select box using ajax in struts2?
it by assigning to the block list select box. so please help me..its urgent...how to operate on select box using ajax in struts2?  I am doing...();" list="dist_list" label="District" headerKey="-1" headerValue="--Please Select--">
how to operate on select box using ajax in struts2?
how to operate on select box using ajax in struts2?  I am doing... it will retrieve me all the blocks under it by assigning to the block list select box. so please help me..its urgent ... thanx in advance
action for dropdown box - Java Server Faces Questions
for populating a list box from a drop-down selection? What I want to do is give... a selection from the drop-down list, the list box beside it gets populated... from my table. When the user selects one catagory, the list box gets populated
dropdown box in jsf - Java Server Faces Questions
dropdown box in jsf  Hi friends, AssigningJob... box... part" List countryList= new ArrayList(); List cityList= new ArrayList
AutoSuggestion Box in Java Swing
Auto Suggestion Box in Java Swing In this section, you will learn how to create autosuggestion/autocomplete box in java swing. For this, we have created combo box and add array of countries using DefaultComboBoxModel to it. Now
Select functionality of drop down list - Struts
(in struts application) in which if user select HIDE from the drop down list it will hide the Text message box which is below it. Description:- Suppose i have Drop down list having element Test1,Test2,Test3,HIDE and one Text msg box
populating text box using jsp code
populating text box using jsp code  Sir, How to populate related values in a text box after selecting value from drop down list using JSP and mysql. I tried using Ajax from your example. But for some browser it does not support
How to add a DropDown List in Flex DataGrid
How to add a DropDown List in Flex DataGrid  hi I am trying to add... the drop down list, the Item that I have selected is not reflected or did... asking for. But combo box is editable, I do not want the user to edit but just
How to implement ajax in struts2 to operate on select box in jsp
by assigning to block list select box... plz help me .. its urgent .. thanx in advance...How to implement ajax in struts2 to operate on select box in jsp  I...="block();" list="dist_list" label="District" headerKey="-1" headerValue="--Please
How to add a DropDown List in Flex DataGrid
How to add a DropDown List in Flex DataGrid  hi I am trying to add... the drop down list, the Item that I have selected is not reflected or did... asking for. But combo box is editable, I do not want the user to edit but just
Flex Combo Box example
Flex Combo Box example       In this tutorial page you will be taught to utilize ComboBox... example. This control shows the drop-down list of data you passed as String inside
Use of Select Box to show the data from database
Use of Select Box to show the data from database       Example program using Select Box to show retrieved data from database This example will describe you the use of Select Box in a JSP
HTML in the box
HTML in the box  Can I use any HTML in the box
input box
input box  give me the code of input box in core java

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.