473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help on onchange event for refreshing the page

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.
Nov 19 '08 #1
1 4360
On Nov 19, 2:55*am, ruds <rudra...@gmail.comwrote:
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."
Nov 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Eghbal | last post by:
Hi all, I'm trying to use the following script: <script language="javaScript"> function setrepto(){ document.aForm.repno.value = document.aForm.rep.options.value; } </script>
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
1
by: dan baker | last post by:
I am pretty much a newbie with javascript, and would like to get a little clarification on what I can do with an onChange javascript event handler. I have a dynamic page I build with perl and...
1
by: MonkeyBoy | last post by:
I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only). Something like.. var tmpHTML = oTable.outerHTML // do something to the HTML her oTable.outerHTML =...
1
by: José Carlos | last post by:
Hi. I have an array with mysql´s data. I have used this array with several text box in a formulary. My question is: How could i use the event onchange to make a function which update the...
5
by: subhodey | last post by:
Hello, I have a ColdFusion online application that has a page having 2 textboxes. Corresponding to these 2 textboxes I have a Custom tag in coldfusion where the textbox is defined by <input...
4
by: auslandt | last post by:
I have an HTML file that includes a JavaScript. I would like this JavaScript to be able to create an "onChange=<function>" attribute against the password element. Here is an example page of the...
17
by: NYXX | last post by:
I wanna know how its possible to clone this website. www.writesomething.net I just want the actual programming code and files. I'm going to ceate a fully interactive website for users to input...
7
by: robtyketto | last post by:
Greetings, I'm slowly building up code to do the following:- Display TWO selection option boxes (cascading). If the FIRST selection option box changes then reload the jsp using onchange...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.