Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how to select values for second drop down depending upon value of first drop down

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi can any one help me.
I am trying to select value for my first drop down from the data base[i.e dynamic drop down which will display all the country names]. Depending upon the value you have selected for the first drop down I would like to show all the related data in the second drop down[i.e. all the states for the selected country].
Here is the code:& lt%@page import="java.sql.*"%>
& lthtml>
& ltbody>
& lt% String state = request.getParameter("state"); out.println(state);%>
& ltform name="my" action="abhay.jsp" method="post">
Country Name:& ltselect value=state onchange="my.submit();">
& lt%
Connection con = null;
Statement st = null;
ResultSet rs = null;
con = DriverManager.getConnection("jdbc:odbc:abhay","root","root");
st = con.createStatement();
String sa="select cname from cname";
rs = st.executeQuery(sa);
String y = rs.getString("cname");
& ltoption value="& lt%= y%>">& lt%= y%>& ltoption>
& lt%
catch(Exception e)
state= request.getParameter("state");
& lt/select>
& lt/form>
& ltform name="m">
& lt%
String h = request.getParameter("state") ;
& lt/form>
& lt/html>
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way we're accomplishing this is:
1. get the values of the countries in your servlet in the backend, and send that collection to the JSP for rendering.
2. based on the selection from that collection, make an AJAX call to the backend to get the states for that country with the country passed as a parameter, and then populate the second drop-down.

Here's a quick AJAX example that might help.
I'm still in control here. LOOK at this tiny ad!
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic