jsp code


jsp code

my requirement is generate dynamic drop down lists, if first drop down list is selected getting that value, based on that value the second drop down list is displayed from mysql data base table by using select statement?
pls provide code how to get first selected drop down list value to generate second drop down list by using jsp?

pls ?
View Answers

June 1, 2010 at 11:49 AM

Hi Friend,

Try the following code:

<%@ page language="java"%>
<%@ page import="java.sql.*"%>
function city(){
var cid=document.getElementById("country").selectedIndex;
var val = document.getElementById("country").options[cid].text;
Connection conn = null;
ResultSet rs =null;
Statement st=null;
String query="";
int cid;
String value=request.getParameter("value");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
st = conn.createStatement();
rs = st.executeQuery("select * from country");
<select id="country" onchange="city();">
<option value="0">--Please Select--</option>
<option value="<%=rs.getString("countryname")%>"><%=rs.getString("countryname")%></option>
<% if(rs.getString("countryname").equals(value)){%>
<option value="<%=value%>" selected disabled><%=value%></option>
rs=st.executeQuery("select * from city where country='"+value+"'");
<option value="<%=rs.getString("city")%>" ><%=rs.getString("city")%></option>

For the above code, we have created following database tables:


CREATE TABLE `country` (
`countryid` bigint(30) NOT NULL auto_increment,
`countryname` varchar(40) default NULL,
PRIMARY KEY (`countryid`)

2) 'city'

`id` bigint(40) NOT NULL auto_increment,
`country` varchar(100) default NULL,
`city` varchar(40) default NULL,



Related Tutorials/Questions & Answers:
jsp code
jsp code  what are the jsp code for view page in online journal
JSP CODE  what is the code for downloading images from database using JSP?   Please visit the following link: http://www.roseindia.net/jsp/downloadimage.shtml
jsp code
jsp code  hi i am Ruchi can anybody plz tell me the jsp code... visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml www.roseindia.net/jsp/searchbook.shtml
jsp code
jsp code  i want health management system project code using jsp.its urgent
JSP CODE  Please help me as soon as possible.Its Urgent. I am working on my college ALUMNI PORTAL. I want to have a ADD FRIEND option in a user's profile. Please send me code
jsp code
jsp code  i want to jsp code which are working as,i have three drop down menu 1st menu for class second menu for subject and third menu as chapter... according to selectde menu,,,,please send me such type code,,,,plz help me
jsp code
jsp code  how to display date in drop down list by jsp thus the date start from current date and for next year it has to check leap year function to february then it display 30 for some months else 31 for other months
JSP code
JSP code  I get an error when i execute the following code : <... = con.createStatement(); st.executeQuery(query); %> <jsp:forward page="address.jsp"></jsp:forward> HTTP Status 500 - type Exception report message
code in jsp
code in jsp  hi.. I had started a project on college admission system in which two operators has been introduced one is admin who can view all... want a code to sort a list of students on the basis of there 12% marks and AIEEE
insert code jsp to access
insert code jsp to access   insert code jsp to access
JSP code for forget password
JSP code for forget password  I need forget password JSP code.. example http://www.roseindia.net/users/forgotpassword.html
jsp code for shopping cart
jsp code for shopping cart  please provide me the jsp code for online shopping cart
tree using jsp code
tree using jsp code  i want to draw a tree structure of a family hierarchy using jsp code
JSP code problem - JSP-Servlet
JSP code problem  HI.. I have a DB2 stored procedure wich return a result set. I have made a report basing on this procedure using Crystal Reports. How to pass parameters to this procedure with java code in a JSP page
need JSP Code.
need JSP Code.  **Hi I need JSP code for selling Products which are in Database. Please can any one help for this.URGENT... Thank You..! Abhijeet
source code in jsp
source code in jsp  i need the source code for online payment in jsp
JSP code for registration form
JSP code for registration form  Haiiii can u please tell me how to encrypt password field in registration form and to compare both password and confirm password fields using jsp
JSP loggin code
JSP loggin code  HI, Please assist me with a JSP code for logon,there should be the Remember me option for both username and password and Remember username for the username. Thank you
Need a JSP CODE  *Hi I need JSP source code for selling products which are in database.. please can any one help me ..URGENT* Thank You
source code in jsp
source code in jsp  how to insert multiple images in jsp page of product catalog
jsp code plz
jsp code plz  write jsp code which takes student roll number as input...;Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/jsp/popup-window-using-ajax-in-jsp.shtml The above links
forgot password code in jsp
forgot password code in jsp  forgot password code in jsp   Please visit the following link: http://www.roseindia.net/jsf/richfaces
Regarding JSP code
Regarding JSP code   hello sir tell me the way to navigate different... interfaces in JSP code I am using Oracle 10g database .Exactly problem with me is that i cant be able to write the code for navigate different users from same login page
Jsp code for disabling record.
Jsp code for disabling record.  I want a Jsp and servlet code for the mentioned scenario. Q. A cross sign appears in front of each record, click to disable the record.System marks the record as disabled.The record
code - JSP-Servlet
code  hi sir my question is i have created a html ang jsp code.... how to write the code to accept an existing id and password.  Hi Friend, Try the following code: 1)login.html: Login
part of AES code in JSP
part of AES code in JSP  org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 19 in the jsp file...-tomcat-5.5.17_base\work\Catalina\localhost\yep.jsp\org\apache\jsp\index_jsp.java:142
javascript Code - JSP-Servlet
javascript Code  how to count controls in form and find no of contriols in html or jsp page.for example one table is there with 10 rows,each row consists of 3 fields as 2 text box and one drop down box
Need a jsp code
Need a jsp code  I need a jsp code in which when i select a value.....please help me for this.   The given code retrieves the employee name...)For the above code, we have created following table: CREATE TABLE `employee
secure online payment code for jsp
secure online payment code for jsp   how to implements online payment in jsp
java/jsp code to download a video
java/jsp code to download a video  how can i download a video using jsp/servlet
source code in jsp
source code in jsp  sir...i need the code for inserting images into the product catalog page and code to display it to the customers when they login to site..pls help me