Javascript iterate through java.util.List

I have an issue with the List-collection.

Situation:

I have 2 dropdownlists, whom are connected to each other. When you select an option in DDL1, the values in DDL2 have to change.

Lets say that we have several football leagues, each with it's own teams. DDL1 contains the football leagues (lame example, I apologize :)). When you select a league, DDL2 must contain all the teams who play in that particular league.

In my servlet, I retrieve the 2 Lists as java.util.List. Is there an elegant way to pass those lists to the JSP-page, in a way so I can perform the actions described above? What I want to do is when a user selects a league, I iterate with javascript through the second list and populate DDL2 with the appropriate teams.

I want to do this without Ajax, if it's possible.

I know that this topic is more javascript-related, but I didn't know where to put it. Moderators can move it, if they want.

[956 byte] By [Bjorn-a] at [2007-11-26 20:04:43]
# 1

sample snippet that will helps you!

<FORM name="back">

<SELECT name="g" onChange="change()">

<%

ListIterator listItr = list.listIterator();

int i=1;

while(listItr.hasNext()) {

Object obj = listItr.next();

i++;

%>

<OPTION VALUE="league"+i SELECTED><%=obj.toString();%>

<%}%>

</SELECT>

</FORM >

<script language="Javascript">

function change() {

box = document.forms[0].g;

destination = box.options[box.selectedIndex].value;

}

</script>

pass the DESTINATION to query the database and populate the 2nd box

cvasu4a at 2007-7-9 23:05:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I prefer not to use scriptlets. Thanks for the solution anyway.
Bjorn-a at 2007-7-9 23:05:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
if you want to implement the solution through javascript this is the only known way as per my knowledge.What about Duke stars?
cvasu4a at 2007-7-9 23:05:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
perhaps you must give him a pure html solution to get your stars :]
alban.maillerea at 2007-7-9 23:05:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
really ! I dont think so! he should allot all the dukes to me only if he stick to his requirement and accordingly my solution is the only way and is the best!:) Html is for static data only , populations etc fundoo dont work with HTML and plelase dont mislead the guy.
cvasu4a at 2007-7-9 23:05:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...