Connecting Tech Pros Worldwide Help | Site Map

Help on onchange event for refreshing the page

  #1  
Old November 19th, 2008, 08:05 AM
ruds
Guest
 
Posts: n/a
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[i]%>"><%=states1[i]%></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.
  #2  
Old November 19th, 2008, 08:15 AM
David Mark
Guest
 
Posts: n/a

re: Help on onchange event for refreshing the page


On Nov 19, 2:55*am, ruds <rudra...@gmail.comwrote:
Quote:
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.
Quote:
My code is:
<HTML>
<HEAD>
<SCRIPT language=javascript>
Lose the language attribute. Use type="text/javascript".

Quote:
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.
Quote:
* var HREF="./GetInfo.jsp?Ctry='"+ctry+"'"
Why CAPS? And why the funny URI?
Quote:
* window.open(HREF, "_self")}
Is this running in a frame?
Quote:
>
</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]
Quote:
>
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."
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax Postback From JavaScript Peter answers 4 June 27th, 2008 09:07 PM
Refreshing a Web Page using Javascript Jimbo1 answers 2 December 4th, 2007 12:05 AM
php and ajax dynamically created select box onchange event Leena P answers 21 October 9th, 2007 12:34 PM
Javascript Application Help with writing text file NYXX answers 17 July 23rd, 2007 05:10 AM