473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

option value structure

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
5 1177
acoder
16,027 Expert Mod 8TB
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
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
16,027 Expert Mod 8TB
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
Genius!

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

Big Thanks.
Jan 9 '08 #5
acoder
16,027 Expert Mod 8TB
You're welcome. Glad I could help.
Jan 9 '08 #6

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

Similar topics

2
by: LC's No-Spam Newsreading account | last post by:
I have a form arranged in a table (you can see an example in the page http://cosmos.mi.iasf.cnr.it/~lssadmin/Website/LSS/Help/query.html) The table is on three columns but has a structure like...
10
by: David | last post by:
Can anyone give me a quick code snippet (that is standards-based) for adding OPTION tags to a SELECT dynamically. I have no problem doing it in IE but I am kind of new to the whole standards world...
1
by: Eduardo Garcia-Prieto | last post by:
I have come accross a problem in using the Interlocked.Exchange(Object, Object) method while using Option Strict On in my project. I have a private class structure variable which can be updated...
3
by: Scott M. | last post by:
Why is it that even with Option Strict turned on I am allowed to use non-string values in strings without having to cast the non-string type to a string? For example, when writing to the console...
4
by: zacks | last post by:
A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged...
2
by: active | last post by:
When I try to code with Option Strict On I run into obstacles. As a simple example, trying to read into a structure. Below "List" is a structure that has been written to a file and now I'd like...
5
by: active | last post by:
RecIn is a structure FileGet(FileNum, RecIn, mNumb) works if I have Option Strict Off File was written by
2
by: Manish Tomar | last post by:
Hi All, As far as my understanding of HTML DOM aka DHTML goes, is that if the DOM structure of HTML document is changed programmatically using JavaScript in the browser, it immediately gets...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.