473,394 Members | 2,160 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 dropdown selected value after onchange in JSP

I have a dropdown list. When I select a value, the page is refreshed. Then, the combo box is still showing the default value. What I want is to maintain the selected value inside combo box even after onchange.
Here is the code ....

Expand|Select|Wrap|Line Numbers
  1. <select size="1" name="ddlSelect" id="ddlSelect" onchange="fnChange(this.value)" > 
  2. <option value="0">--- Select One ---</option> <%  
  3.     String selectedname="";                          
  4.     ArrayList<Profile> userlist = Controller.UserNameList(Profile.userId,year);                                
  5.     for (Profile j : userlist) {         
  6.         selectedname = (!cbmUtil.isNull(j.userName)) ? "selectedname" : "";
  7.         out.write("<option " + selectedname + " value='" + j.userName + "'>" + j.userName + "</option>");
  8.     }
  9. %> </select> <script type="text/javascript">
  10. function fnChange(Index){
  11.         var userName = $("#ddlSelect option:selectedname").val();                                
  12.         if(!userName){return false;}   
  13.             document.location.href="testpage.jsp?fn=pChange&userName="+userName;
  14.         }
  15. </script>
Sep 9 '14 #1
3 5845
Dormilich
8,658 Expert Mod 8TB
the appropriate attribute is called selected not "selectedname".
Sep 9 '14 #2
Dormilich,

Thank you for your reply.
Sorry, it is just typo error. Although it is with option:selected , result is the same.
Sep 10 '14 #3
Dormilich
8,658 Expert Mod 8TB
moving to java (jsp) forum.
Sep 10 '14 #4

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

Similar topics

0
by: Kannan.M.R | last post by:
Hi, I have a problem in assigning the selected value in the dropdown to a hidden control. It goes like this. I have a repeater control. In the repeater control’s item template, I have a...
2
by: tmeister | last post by:
I must be missing something obvious. I have a drop down list in asp.net and it populates the states from a database. When I view the source of the page I get the standard option tags with the...
2
by: siaj | last post by:
Hi..Me New to ASP.NET I am trying to get the selected value from the dropdownlist but I m always getting the first selected value ...I am giving the code down ... <asp:dropdownlist...
1
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in...
2
by: rk330 | last post by:
Greetings I have a drop down list populated by my sql server database. The data on this ASP page consists of numbers that I use to calculate a grand total. This is performed by a javascript...
3
by: John | last post by:
I have two dropdown lists that I have bound to a datatable and set the DataTextField and DataValueField for. Both lists show the values I expect from the database. However, when I need to access...
5
by: temijojo | last post by:
Hello, Can someone help me in this problem. In my content page, I used 2 user controls inside an Ajax Toolkit TabControl. One of the user controls is a data entry with a dropdownlist. The...
1
by: techbytes | last post by:
hi, I have 2 dropdowns ,after populating the dropdown with selected values,the page is refreshed. so the selected value in the dropdown is not retained in the dropdown list. I want to retain...
1
by: kunal choudhary | last post by:
hi, I have created a form (in ASP.NET and C#) which have 5 dropdown 1.3rd dropdown fill on the basis of 1st n 2nd dropdown value 2.5th dropdown fill on the basis of 4th dropdown value I...
1
by: nu123 | last post by:
I'm using codeigniter to create my php web site in my view page I need to set visible when the drop-down value change how can i do that? this the button that i need visible and hidden when drop-down...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.