This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Select tag 's selection should persist. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Select tag Watch "Select tag New topic

Select tag 's selection should persist.

mallika shah
Ranch Hand

Joined: May 11, 2006
Posts: 164

I have some code like this:

<select name="selections">
<option value="option0">Select One</option>
<option value="option1">Option1</option>
<option value="option2">Option2</option>

<input type="textbox" name="text1">

and a submit button.
When you click the submit button, based on options and text entered,the results page would be displayed, with the drop down and text box again on the page.
What i want is: If the user selected Option1 in the drop down, that search type should remain until the user either changes the selection or ends their session.
But i find that the first option comes back again.

how can i achieve this functionality?

shiva sarna

Joined: Jul 23, 2006
Posts: 23

are you using any frame work? It is possible to set form elements in struts.

If it is plain jsp, try setting 'option' in a session.

<option selected>session element goes here</option>

so what ever the user selects is set in a session and when he comes back he sees that option in the drop down list.



SCJP 5.0
I agree. Here's the link:
subject: Select tag 's selection should persist.
Similar Threads
post form data when slection changed in list
JSTL tags
Javascript Dynamic Dropdown Box validation
to get all required fields in single page
Show a hidden text field