File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How Drop Down Box values can be retained Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How Drop Down Box values can be retained " Watch "How Drop Down Box values can be retained " New topic
Author

How Drop Down Box values can be retained

Dinesh Remje
Ranch Hand

Joined: Jan 26, 2010
Posts: 57
Following is the code i have written in JSP and is working fine when javascript is turned on.
Now i have done Java validation also. Now it work perfectly fine showing the error. The only thing i need here is that i want to retain the value which will be selected by user when javascript is turned off.
I am able to retain the value when javascript is on. So how can i do that.
Following is the code which i have written


There are in all 10 values with their respective values so how can i do that. Please help me. How can i retain the selected value even after the form is refreshed.
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

What I understand is, you want to display the selected value for list.

you can use the selected attribute of the option tag, and display the selected option based on what user has selected.

When form is submitted, you can check for the selected designation and based on that put selected on an option



[Servlet tutorial] [Servlet 3.0 Cook Book]
Dinesh Remje
Ranch Hand

Joined: Jan 26, 2010
Posts: 57
No i want to retain value that will be selected by user.
Right now i m able to retain the "Select Designation" value as i have set it.
But i need to retain value that will be selected by the user from the list i.e HOD, Assistant Professor etc
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 514
hi,
You have to put the selected value in the HttpSession.
And while rendering the screen again , within that JSP add the SELECTED attribute to it based on the match between session value and the one of the values in the dropdown.

Regards,
amit
Dinesh Remje
Ranch Hand

Joined: Jan 26, 2010
Posts: 57
thanks Amit,

Ya was able to do it.
What i have done is stored all the values in an 2D array and called those value in for loop and in if condition i checked whether that value is selected.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Drop Down Box values can be retained