Help on onchange event for refreshing the page

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.
 
D

David Mark

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.

From the what of the what? You need to ask in a JSP group.
My code is:
<HTML>
<HEAD>
<SCRIPT language=javascript>

Lose the language attribute. Use type="text/javascript".

function Select_Index(form)
{
  var ctry = document.f1.Cntry.options
[document.f1.Cntry.selectedIndex].value

Don't assume that a form can be referenced as a property of the
document object (use the forms property.) Similar problem with
elements.
  var HREF="./GetInfo.jsp?Ctry='"+ctry+"'"

Why CAPS? And why the funny URI?
  window.open(HREF, "_self")}

Is this running in a frame?
</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>
<%
  }
%>

Don't post server side code mixed with client side code (even if they
are both Javascript.)

[snip]
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.

Start by expounding on "not happening."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top