
you need to create two tables: country(countryid Number,countryname text) and state(stateid Number countryid Number, statename text);
1)country.jsp:
<%@page import="java.sql.*"%>
<html>
<head>
<script language="javascript" type="text/javascript">
var xmlHttp
var xmlHttp
function showState(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
} else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
} if (xmlHttp==null){
alert("Browser does not support XMLHTTP Request")
return;
}
var url="state.jsp";
url +="?count=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("state").innerHTML=xmlHttp.responseText
}
}
</script>
</head>
<body>
<select name='country' onchange="showState(this.value)">
<option value="none">Select</option>
<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student"); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from country");
while(rs.next()){
%>
<option value="<%=rs.getInt("countryid")%>">
<%=rs.getString("countryname")%></option>
<%
}
%>
</select>
<br>
<div id='state'>
<select name='state' >
<option value='-1'></option>
</select>
</div>
</body>
</html>
2)state.jsp:
<%@page import="java.sql.*"%>
<%String country=request.getParameter("count"); int id=Integer.parseInt(country); String buffer="<select name='state'><option value='-1'>Select</option>";
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from state where countryid="+id+" ");
while(rs.next()){
buffer=buffer+"<option value='"+rs.getInt("stateid")+"'>"+rs.getString("statename")+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
} catch(Exception e){
System.out.println(e);
}
u had sent me this code... but the down drop down menus are being displayed at the same place.. i want them at different places.. so how can i do that?