aspose file tools*
The moose likes Servlets and the fly likes Simple JSP question...Please help??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Simple JSP question...Please help???" Watch "Simple JSP question...Please help???" New topic
Author

Simple JSP question...Please help???

Moined Mogul
Ranch Hand

Joined: Jul 11, 2001
Posts: 33
I have the below piece of code that creates a drop down menu in my JSP page. This may seems like a very silly question but how would you preselect say the 4th item in the list so that on start up the JSP would open with the 4th item selected.
Thanks very much for any assistance you can give.
<%-- Populate the pulldown list of resource titles from the database. --%>
<%
String[] ResourceTitle = Functions.getTitleList();
if (ResourceTitle != null)
{
for (int i=0; i < ResourceTitle.length; i++)
{
if (ResourceTitle.equals (strSelectedResource))
{
//If the string in the strSelectedResource is
//in the pulldown list use it as the
//Preselected option to display.
%>
<OPTION selected value="<%= ResourceTitle %
>"> <%= ResourceTitle %> </OPTION>
<%
}
else
{
%>
<OPTION value="<%= ResourceTitle %>"> <%=
ResourceTitle %> </OPTION>
<%
}
}
}
else
{
%>
<OPTION> No Titles Loaded </OPTION>
<%
}
%>
</SELECT>
</td>
Jeff Sunder
Ranch Hand

Joined: Jun 26, 2001
Posts: 47
I beleive all you have to do is add'SELECTED' to the first block of your if statment:

if (ResourceTitle.equals (strSelectedResource))
{
//If the string in the strSelectedResource is
//in the pulldown list use it as the
//Preselected option to display.
%>
<OPTION selected value="<%= ResourceTitle %
>"> <%= ResourceTitle %> SELECTED</OPTION>
<%
}
else
{
%>
<OPTION value="<%= ResourceTitle %>"> <%=
ResourceTitle %> </OPTION>
<%
}
Dipti Alurkar
Greenhorn

Joined: Jul 05, 2001
Posts: 7
I think that you need to add the index of the ResourceTitle array in the 'if'.
if (ResourceTitle[i].equals (strSelectedResource))
this might help.
the 'SELECTED' word is already included in the <OPTION> tag.
Dipti
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple JSP question...Please help???