By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

option value structure

P: 57
I am looking for alternatives on storing menu option lists rather than the current process method. On a jsp form, there must be a cleaner way to store the user selection outside of the below and not using cookies.

Suggestions and comments are welcome... tks

Expand|Select|Wrap|Line Numbers
  1.  -- html
  2. <%
  3.     String  countOptions= request.getParameter("countOptions");
  4.         if(countOptions == null)
  5.         {
  6.             countOptions = "30";
  7.         }    
  8. %>
  9.  
  10. Count Options
  11.  
  12. <%  if(countOptions.equals("10")) { %> 
  13.          <select name="countOptions">
  14.     <option value="10" selected="yes"> 10 </option>
  15.     <option value="20"> 20 </option>
  16.     <option value="30"> 30 </option>
  17.          </select>
  18. <% }
  19.        if(countOptions.equals("20")) { %> 
  20.         <select name="countOptions">
  21.     <option value="10"> 10 </option>
  22.     <option value="20" selected="yes"> 20 </option>
  23.     <option value="30"> 30 </option>
  24.          </select>
  25. <% }
  26.         if(countOptions.equals("30")) { %> 
  27.           <select name="countOptions">
  28.     <option value="10"> 10 </option>
  29.     <option value="20"> 20 </option>
  30.     <option value="30" selected="yes"> 30 </option>
  31.          </select>
  32. <% }
  33.  
  34. ---------------- form 2 --------------
  35. <%
  36. <input type="hidden" name="countOptions"  value="<%=countOptions %>">
  37. %>
  38.  
-- html
Jan 8 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
I am looking for alternatives on storing menu option lists rather than the current process method. On a jsp form, there must be a cleaner way to store the user selection outside of the below and not using cookies.
What do you mean by storing? How are you planning to use these values - across a number of pages?

There's a bit of redundancy in your code. You only need the select element once and use the JSP within each option tag unless you don't like to mix server-side and HTML too much.
Jan 8 '08 #2

P: 57
You’re on the right trail. The redundancy is actually what I want to remove.
Right now I code "selected" for each individual menu option. On submit, the page is rendered with new information but still contains the menu options. If each menu option is not coded like the above the user selection is lost and a default is used.
Jan 8 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You could try something like:
Expand|Select|Wrap|Line Numbers
  1. <select name="countOptions">
  2.     <option value="10" <%  if(countOptions.equals("10")) { %>selected="yes"<% }%>> 10 </option>
  3.     <option value="20" <%  if(countOptions.equals("20")) { %>selected="yes"<% }%>> 20 </option>
  4.     <option value="30" <%  if(countOptions.equals("30")) { %>selected="yes"<% }%>> 30 </option>
  5. </select>
Jan 9 '08 #4

P: 57
Genius!

Works perfectly and very clean.
Hundreds of lines of code have been cleaned up.

Big Thanks.
Jan 9 '08 #5

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad I could help.
Jan 9 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.