• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with Drop Down list

 
Don Martino
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an ArrayList that I am creating in a java class containing unix file names. That part is working correctly.
I need to be able to load the ArrayList into a drop down list using an html select.
Any ideas? Could you give me an example? I'm not using struts, jst a jsp using html tags.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pass the list from your page controller to the JSP as a request-scoped variable, then use the JSTL <c:forEach> tag to iterate over the list and create an <option> element for each entry.
 
Don Martino
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code that I came up with. Everything works except the document.write. Could you show me how to define the option tag where it will print out correctly?

<td>
<select name="anncFile" onChange="">
<script language="JavaScript" type="text/javascript">

<%
ArrayList tarFileList;
tarFileList = (ArrayList) mauMainForm.getTarFileList();
if (!tarFileList.isEmpty()) {
String tarFileName;
int size = tarFileList.size();
for (int i=0; i < size; i++){
tarFileName = (String) tarFileList.get(i);
%>
document.write("<option value="+<%=tarFileName%>+">"+<%=tarFileName%>+"</option>");
<%
}
}
%>

</script>
</select>
</td>
 
Don Martino
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To simplify question. Could somebody show me correct syntax for following document.write?

document.write("<option value="+<%=tarFileName%>+">"+<%=tarFileName%>+"</option>");
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the document.write at all? It's completely superfluous and just adding complexity for no reason.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!