• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple JSP question...Please help???

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
<%
}
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic