0

Hey guys!!! (and gals)...

Uhhmmm... I'm in a bit of a tiffy... Im trying to populate a drop down list with data in my query browser. But I AM NOT USING JAVASCRIPT...mostly because i havent learned it...but im trying to a certain table from the query browser to my drop down...

Thanks in advance! :)

3
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by oonebaddog
0

well, you don't actually need javascript to do that.
since you are posting in the jsp forum, I assume the jsp/servlet combo would serve you best.
do you know anything about java coding?

0

Create a method in a class that executes the select query and retrieves the data. Save those data in an ArrayList.

In your jsp call that method and with a combination of html and java (scriplet) populate the drop down box

JSP:

<%
ArrayList list = yourClass.getData();
int size = list.size();
%>

<select name="someName">
<%
for (int i=0;i<size;i++) {
  String s = (String)list.get(i);
%>
<option value="<%=s%>" ><%=s%></option>
<%
}
%>
</select>

If the above code is confusing or doesn't make sense then you should do more studying about JSPs and html

Also you should already know how to run queries or use java core methods before going to JSP.
For your method that runs the query, better create a class that has a combination of 2 attributes (value, text). The ArrayList should have elements not Strings but of the class you created. When you run the query you would need a value to display and a value to use at the <option> :

JSP:

<%
ArrayList list = yourClass.getData();
int size = list.size();
%>

<select name="someName">
<%
for (int i=0;i<size;i++) {
  YourClass obj = (YourClass)list.get(i);
%>
<option value="<%=obj.getValue()%>" ><%=obj.getText()%></option>
<%
}
%>
</select>

You should know how to create your own classes and how to use them (get/set methods)

0

well, you don't actually need javascript to do that.
since you are posting in the jsp forum, I assume the jsp/servlet combo would serve you best.
do you know anything about java coding?

uhmmm...i now somethings... but not alot... i can link pages using only jstl.

0

uhmmm...i now somethings... but not alot... i can link pages using only jstl.

lik <c:import>'s and stuff...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.