R
ruds
Hello,
I have a JSP page in which HTML form elements are present.
I have a drop down list named Country, when a user selects his country
I want another drop down list to populate based on the first list the
names of coresponding states in that country.
For this I want to retrive values from database onchange event of the
first drop down list.
My code is:
<HTML>
<HEAD>
<SCRIPT language=javascript>
function Select_Index(form)
{
var ctry = document.f1.Cntry.options
[document.f1.Cntry.selectedIndex].value
var HREF="./GetInfo.jsp?Ctry='"+ctry+"'"
window.open(HREF, "_self")
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE>
<TR>
<TD>Country</TD>
<TD><select name="Cntry" size="1" onchange="Select_Index(this.FORM)">
<%
rs=stmt.executeQuery("select * from Country");
while(rs.next()){
String cnt=rs.getString(2);
%>
<OPTION VALUE="<%=cnt%>"><%=cnt%></OPTION>
<%
}
%>
</select> </TD> </TR>
<TR>
<TD>State</TD><TD><select name="state" size="1">
<OPTION VALUE="" selected></OPTION>
<% rs=stmt.executeQuery("select ID from Country where
Country="+Cntry);
while(rs.next()) {int cid=rs.getInt(1); }
String states1[]=new String[50];
int j=0;
rs=stmt.executeQuery("select State from States where
CID="+cid);
while(rs.next()) {
states1[j]=rs.getString(1);
j++; }
for(int i=0;i<states1.length;i++)
{ %>
<OPTION VALUE="<%=states1%>"><%=states1%></OPTION>
<% } %>
</select> </TD> </TR>
</TABLE>
</BODY>
</HTML>
As given in the above code onchange event of first drop down my
Select_Index function is called which reopens the page with attribute
ctry as parameter which is used in turn to populate my second drop
down list.
But this is not happening, please tell me how to achieve the same.
I have a JSP page in which HTML form elements are present.
I have a drop down list named Country, when a user selects his country
I want another drop down list to populate based on the first list the
names of coresponding states in that country.
For this I want to retrive values from database onchange event of the
first drop down list.
My code is:
<HTML>
<HEAD>
<SCRIPT language=javascript>
function Select_Index(form)
{
var ctry = document.f1.Cntry.options
[document.f1.Cntry.selectedIndex].value
var HREF="./GetInfo.jsp?Ctry='"+ctry+"'"
window.open(HREF, "_self")
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE>
<TR>
<TD>Country</TD>
<TD><select name="Cntry" size="1" onchange="Select_Index(this.FORM)">
<%
rs=stmt.executeQuery("select * from Country");
while(rs.next()){
String cnt=rs.getString(2);
%>
<OPTION VALUE="<%=cnt%>"><%=cnt%></OPTION>
<%
}
%>
</select> </TD> </TR>
<TR>
<TD>State</TD><TD><select name="state" size="1">
<OPTION VALUE="" selected></OPTION>
<% rs=stmt.executeQuery("select ID from Country where
Country="+Cntry);
while(rs.next()) {int cid=rs.getInt(1); }
String states1[]=new String[50];
int j=0;
rs=stmt.executeQuery("select State from States where
CID="+cid);
while(rs.next()) {
states1[j]=rs.getString(1);
j++; }
for(int i=0;i<states1.length;i++)
{ %>
<OPTION VALUE="<%=states1%>"><%=states1%></OPTION>
<% } %>
</select> </TD> </TR>
</TABLE>
</BODY>
</HTML>
As given in the above code onchange event of first drop down my
Select_Index function is called which reopens the page with attribute
ctry as parameter which is used in turn to populate my second drop
down list.
But this is not happening, please tell me how to achieve the same.