Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to link 2 dropdown in javascript?

Status
Not open for further replies.

11251995

Programmer
May 18, 2005
12
US
Hi, I have 2 dropdowns, the keys of the hashtable below are the options in dropdown1 and the the values are the superset. Dropdown2 shows the super set initially. By selecting a record(key) in dropdown1, Dropdown2 will show the subset base on the hashtable.

I think I need to add a onChange in 'select1' control, but no luck.

Thanks for any suggestions. - Megan

<body>
<%
Vector vec = new Vector();
vec1.addElement("aa");
vec1.addElement("bb");
vec1.addElement("cc");

Vector vec1 = new Vector();
vec1.addElement("aa11");
vec1.addElement("bb11");
vec1.addElement("cc11");

Vector vec2 = new Vector();
vec2.addElement("aa22");
vec2.addElement("bb22");
vec2.addElement("cc22");

Vector vec3 = new Vector();
vec3.addElement("aa33");
vec3.addElement("bb33");
vec3.addElement("cc33");

Hashtable hash = new Hashtable();
hash.put("aa",vec11);
hash.put("aa",vec22);
hash.put("aa",vec33);

Vector vecAll = new Vector();
vecAll.addElement("aa11");
vecAll.addElement("bb11");
vecAll.addElement("cc11");
vecAll.addElement("aa22");
vecAll.addElement("bb22");
vecAll.addElement("cc22");
vecAll.addElement("aa33");
vecAll.addElement("bb33");
vecAll.addElement("cc33");

%>

This is my JSP page. <br>
<% out.println("Hello my world");%>
<form action="HelloWorldServlet" method="post">

<SELECT NAME="select1" >
<%
for (int i = 0; i < vec.size(); i++) {
String content = (String)vec.elementAt(i);
%>
<option value="<%=content%>"><%=content%</option>
<%
}
%>
</SELECT>
<------------------->

<SELECT NAME="select2">
<%
for (int i = 0; i < vecAll.size(); i++) {
String content = (String)vecAll.elementAt(i);
%>
<option value="<%=content%>"><%=content></option>
<%
}
%>
</SELECT>
</form>
</body>
 
You really should show your client-side code... that aside, this has been covered more times than I can remember recently, so it would probably be worth checking out the FAQ section, and also searching the posts.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top