1,105,221 Community Members

Populating a Drop Down box with Data in SQL

Member Avatar
oonebaddog
Newbie Poster
3 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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! :)

Member Avatar
stultuske
Posting Expert
5,290 posts since Jan 2007
Reputation Points: 935 [?]
Q&As Helped to Solve: 774 [?]
Skill Endorsements: 35 [?]
Featured
 
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?

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
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)

Member Avatar
oonebaddog
Newbie Poster
3 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
oonebaddog
Newbie Poster
3 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article