473,320 Members | 1,863 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,320 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 5838
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.