473,394 Members | 1,817 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,394 software developers and data experts.

How to retain value of dropdown list when it changes?

Hello,

I have a drop-down list that I would like for it to retain the selected value (but it's not working). The following is my code :

Expand|Select|Wrap|Line Numbers
  1.     <select name="trophyscope" size="2" onChange="
  2.     <%String item = (String renderRequest.getPortletSession().getAttribute("trophyscope");
  3.         %>
  4.         <option selected="true" value="<%=item%>">"<%=item%>"</option> 
  5.             "
  6.     > 
  7.  
I wonder if someone could please point me to what I am doing wrong?

Thank you,

Akino
Jan 20 '12 #1
7 3366
Dormilich
8,658 Expert Mod 8TB
since I don’t know that programming I can only answer in general. you need to set that option element as selected, which has the passed value.
Jan 20 '12 #2
C CSR
144 100+
Compared to my stuff, you've got some xtra "" in the value= attribute. See if this fixes it:

Expand|Select|Wrap|Line Numbers
  1. <option selected="true" value="<%=item%>"><%=item%></option>
  2.  
Jan 21 '12 #3
C CSR
144 100+
Actually, its not in the attribute itself. Its what's in between your start and finishing option tags. (Minor mistake in my description--just look at the example).
Jan 21 '12 #4
Hello C CSR,

Thank you so much for your reply. Removing the extra " :

Expand|Select|Wrap|Line Numbers
  1. <option selected="true" value="<%=item%>"><%=item%></option> 
  2.  
allows my code to work. But it adds an extra item to my drop down list. I wonder if you or someone could please tell me how to set
the selected item on a drop down list without adding a new item to
the list?

Thank you again,

Akino
Jan 23 '12 #5
C CSR
144 100+
Akino:

Post a larger section of your code (from <Form to /Form> if you can). Meanwhile I'll look at mine again to see how I avoided that. I wrote mine originally a while back and I've just been cut&pasting ever since.
Jan 23 '12 #6
C CSR
144 100+
If I remove the "option selected" line altogether, I get a blank in the combo before I click the arrow (the same if I leave the line in but put nothing between the >< , regardless of the value= attribute). I find that no matter whether the initial appearance is blank or contains some text, I always see it duplicated (highlighted) at the top of the dropdown when I click (even the blank line) but that's to indicate the current selection if the user doesn't choose something else. This by nature, but does not refer to your question about the duplicate highlighted item along with the same item being shown further down in the list.

What I did in some cases, is put some text in there that is not actually a searchable item, like "Select" for example, and leave my default value in the "option selected" line a preferred value from my list. This way the value is there but what you see is "Select." Then when you click the arrow, all the items in the list appear once, BUT, in keeping with the nature of the combo, the text "Select" is highlighted at the top in the drop list.

So, you either have a highlighted blank line at the top after you click, with nothing showing in the box before you click, or you have "Select" highlighted at the top after you click. But in the list of "true" items, nothing is duplicated. My workaround, to demonstrate, is as follows:

CODE
Valueless text:
<option selected value="<%=item%>"><%Response.write "Select"%></option>

Other option are: Blank

<option selected value="<%=item%>"></option>

OR

no option selected line at all
CODE

I don't think you can eliminate the highlighted duplication of what's already in the combo before you click. Ergo, do you want the combo to first appear blank, put some text in there like "Select item," OR, the 3rd option is to eliminate the "option selected" line completely; then, the first item in your recordset for the list will automatically appear (depending on how you were sorted) , but you still have the duplicate in the highlight, but in the highlight ONLY.

Did you follow all that?
Jan 23 '12 #7
C CSR
144 100+
I hope the Moderaror doesn't tear up my code. I forgot to put it in the "CODE blocks."
Jan 23 '12 #8

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

Similar topics

1
by: Speaker | last post by:
Hi I am a newbie to SQL. I have a historical list of digatal points listed by time.ie: 3 fields PointName;Date/Time;State. I need to return a list of When a specific point chsnges state. ...
1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
0
by: Toonman | last post by:
I have a webpage with a <form> consisting of a large table grid of dropdown lists used to make changes in a database. Some of these dropdown lists have the same value. I'm trying to make it so...
4
by: Justin Bartels | last post by:
Hi, I have been struggling with an unusual problem with a dropdownlist web control for quite some time now. Cutting straight to the problem, I am setting the selected item in the dropdownlist...
2
by: starbuck | last post by:
Hi In asp.net/vb.net is there a trigger for a dropdown list when focus moves to next control. I want other fields to be filled after a user selects a account reference and tabs to the next...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
1
by: fezzabett | last post by:
i have one question. i have two different dropdown list. one to select members,and another one to select department. so i want function when i click on one button for example i named it 'add another...
2
by: dhoward | last post by:
How do you default a dropdown list when a particular item is selected? I have a two drop down lists, one for state and one for county. If the user chooses a state outside of Alabama, I need the...
2
by: rote | last post by:
If you have a look at this site below you will notice that after typing some text and the list is too long the textbox will give you like a dropdown list...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.