
i have three tables in database country,state and city ...when i selected country ten only state show of that country similarly city depends on state i have implmnt dis code and it work propely bt problem is the field which inserted a value before country become erase \when selected country...plz help me sir
<%@page import="java.sql.*" %>
<html>
<head>
<title>New User Registration</title>
</head>
<body bgcolor="#CCFFFF">
<CENTER>
<H1> <u>EDUCATIONAL DATABASE SYSTEM</u> </H1>
</CENTER>
<a href="login.html">Home Page</a>
<%
String strcountrycode = "0";
String strstatecode = "0";
String strcitycode = "-1";
String strstatename = "";
String strcountryname = "";
String strcityname = "";
//checking the state code
if (request.getParameter("param1") != null){
strcountrycode=request.getParameter("param1").trim();
}
if (request.getParameter("param2") != null){
strstatecode=request.getParameter("param2").trim();
}
if (request.getParameter("param3") != null){
strcitycode=request.getParameter("param3").trim();
}%>
<script language="JavaScript" type="text/JavaScript">
//-->
//function for changing the url
function ChangeURL1(FileName,param1){
location.href=FileName + ".jsp?param1=" + param1;
}
function ChangeURL2(FileName,param1,param2){
location.href=FileName + ".jsp?param1=" + param1 + "¶m2=" + param2;
}
function ChangeURL3(FileName,param1,param2,param3){
location.href=FileName + ".jsp?param1=" + param1 + "¶m2=" + param2 + "¶m3=" + param3;
}
function validate()
{
if( document.kk.email.value=="")
{
alert("Email cannot be blank");
return;
}
if( document.kk.name.value=="")
{
alert(" Name cannot be blank");
return;
}
if( document.kk.phone.value=="")
{
alert("Phone Number cannot be blank");
return;
}
if( document.kk.sta.value=="select state")
{
alert("You must select a state");
return;
}
if( document.kk.address.value=="")
{
alert("Address cannot be blank");
return;
}
if( document.kk.pinCode.value=="")
{
alert("PinCode cannot be blank");
return;
}
}
</script>
<form name="kk" method="POST" action="signup.jsp">
<%
Connection conn=null;
try
{
ResultSet rs,rm=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn =DriverManager.getConnection("jdbc:odbc:neha");
PreparedStatement stat,yu;%>
<p align="center">
<b><font size="5"> New User Registration</font></b>
</p>
<div align="left">
<table border="0" width="100%">
<tr>
<td width="23%"><b>Email *:</b></td>
<td width="77%">
<b>
<input type="text" name="email" size="20" tabindex="1">
</b>
</td>
</tr>
<tr>
<td width="23%">
<b>
Name*:</b></td>
<td width="77%">
<b><input type="text" name="name" size="20" tabindex="4">
</b>
</td>
</tr>
<tr>
<td width="23%" height="25"><b>Phone Number*:</b></td>
<td width="77%" height="25"><b><input type="text" name="phone" size="20" tabindex="13"> </b> </td>
</tr>
<tr>
<td width="23%" height="25"><b>Country*:</b></td>
<td width="77%" height="25">
<select name="count" class="Textbox" onChange="ChangeURL1('userentry',document.kk.count.options[document.kk.count.selectedIndex].value);">
<option value=''>select country</option>
<%
stat=conn.prepareStatement("SELECT country,countryID FROM mast_country ");
rs = stat.executeQuery();
while(rs.next())
{
String str1,str2;
str2=rs.getString("countryID");
str1=rs.getString("country");
if(strcountrycode.equals(str2)) {
strcountrycode=str2;
strcountryname=str1;
%>
<option value="<%out.println(str2);%>" selected><% out.println(str1); %>
</option>
<%
}else{%>
<option value="<%out.println(str2);%>"><% out.println(str1); %>
<%
}
}if(rs!=null){
rs.close();
rs=null;
}
%>
</select>
</tr><tr>
<td width="23%" height="25"><b>state*:</b></td>
<td width="77%" height="25"><b>
<select name="sta" class="Textbox" onChange="ChangeURL2('userentry',document.kk.count.options[document.kk.count.selectedIndex].value,document.kk.sta.options[document.kk.sta.selectedIndex].value);">
<option value=''>select state</option>
<%
yu= conn.prepareStatement("SELECT state,stateID FROM mast_state where countryID="+strcountrycode+" ");
rs = yu.executeQuery();
while(rs.next())
{
String str3,str4;
str3=rs.getString("state");
str4=rs.getString("stateID");
if(strstatecode.equals(str4)) {
strstatecode=str4;
strstatename=str3;
%>
<option value="<%out.println(str4);%> " selected >"<%out.println(str3);%>"</option>
<%
}
else{%>
<option value="<%out.println(str4);%>"><% out.println(str3); %></option>
<%}
}if(rs!=null){
rs.close();
rs=null;
}
%>
</select></b></td>
</tr>
<tr>
<td width="23%" height="25"><b>City*:</b></td>
<td width="77%" height="25"><b>
<select name="cty" class="Textbox" onChange="ChangeURL3('userentry',document.kk.count.options[document.kk.count.selectedIndex].value,document.kk.sta.options[document.kk.sta.selectedIndex].value,document.kk.cty.options[document.kk.cty.selectedIndex].value);">
<option value=''>select city</option>
<%
yu= conn.prepareStatement("SELECT city,cityID FROM mast_city where stateID="+strstatecode+" ");
rs = yu.executeQuery();
while(rs.next())
{
String str5,str6;
str6=rs.getString("city");
str5=rs.getString("cityID");
if(strcitycode.equals(str5)) {
strstatecode=str5;
strstatename=str6;
%>
<option value="<%out.println(str5);%>" selected>"<%out.println(str6);%>"</option>
<%
}
else{%>
<option value="<%out.println(str5);%>"><% out.println(str6); %></option>
<%}
}if(rs!=null){
rs.close();
rs=null;
}
%></select>
</b> </td>
</tr>
<tr>
<td width="23%" height="25"><b>Place*: </b></td>
<td width="77%" height="25"><b><input type="text" name="place" size="20" tabindex="11"> </b> </td>
</tr>
<tr>
<td width="23%" height="25"><b>Pin Code*: </b></td>
<td width="77%" height="25"><b><input type="text" name="pinCode" size="20" tabindex="11"> </b> </td>
</tr>
<tr>
<td width="23%" height="25"><b>Address*: </b></td>
<td width="77%" height="25"><b><input type="text" name="address" size="43" tabindex="7"> </b> </td>
</tr>
<tr>
<td width="23%" height="1"></td>
<td width="77%" height="1"> </td>
</tr>
<tr>
<td width="23%" height="21"></td>
<td width="77%" height="21">
<b>
<input type="submit" value="Submit" name="B1" onclick = "validate();" tabindex="13">
</b>
</td>
</tr>
</table>
</div>
<%
}
catch(Exception E)
{
System.out.println("error");
}%>
</form>
</body>
</HTML>
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.