aspose file tools*
The moose likes Servlets and the fly likes How to make a select option selected for a certain option? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to make a select option selected for a certain option?" Watch "How to make a select option selected for a certain option?" New topic
Author

How to make a select option selected for a certain option?

May Hsiao
Greenhorn

Joined: Aug 13, 2000
Posts: 9
If I have a "select"- on my JSP page, it has 5 options. I want to base on the database' data to make a certain option selected. How to write this JSP code? I kmow it only need to type "selected" in the <option ...... selected /option>
kichu kichu
Ranch Hand

Joined: May 10, 2001
Posts: 59
This is a sample code that i have posted,here I'am getting a set of values say RelatedProject names from the database.
Now suppose we pass a RelatedProject name,we have to see if this value we have passed is present in the database or not.
If it is present in the database,then this value should remain selected.
strRelProj1--->Set of projects from database.
strRelProj---->The value that we pass.

<%
//Query to display Related Project Details
sql = "select NAME from XD_ENTOBJ where ENTITY_UID="+intEUID;
//Execute Query
rs = stmt.executeQuery(sql);
while ( rs.next() )
{
String strRelProj1 = rs.getString(1);
if ( strRelProj1.equals(strRelProj) )
{
out.println("<option value=" + strRelProj1+ " selected >"
+ strRelProj1+ "</option>");
}
else
{
out.println("<option value=" + strRelProj1+ " >"
+ strRelProj1+ "</option>");
}
}
%>
hope this helps!!!:-)
Doubts if any are always welcome.
regards,
kichu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make a select option selected for a certain option?
 
Similar Threads
A question about the form
select option in select box
Dynamic selection of <option> in a JSP
how to change select menu dynamically in a JSP
Select box get refresh after populating the data into a table.