My challenge is to show the same value as selected in the Dropdown when the search result is returned.
My Dropdown is builds as following on my JSP Page
<SELECT name="montno" onChange="selectChanged(this);">
<OPTION value="1" selected>1</OPTION>
In procesaction I retrieve the selected values from the hidden field I have added the selected values to.
String sSearchString = request.getParameter("numberoffmonth");
Then I Add it to the response to retrieve it in Process view
What do I have to do so it is selected value when the JSP is visible again.?
mannoj patil wrote:I think you can set the "selected" in the following code dynamically while returning the dropdown list?
...or am I missing something?
What do you mean , if you see in the above html code, it is alreadey selected.
Bu my challenge is how to show value the User has selected afte the Search result is returned.
I could not find this function as a part of javax.servlet.http.HttpServletResponse in j2ee 5.p api library
thomas colding wrote:
Bear Bibeault wrote:Same way. Whatever option has the selected attribute will be the selected option.
Could you please specify what you mean, is it possible?
I'm not sure how I could possibly make it more clear.
Whatever option you put the selected attribute on will be the selected option. This is just basic HTML.
Bear Bibeault wrote:This is just basic HTML.
That's the key thing to understand. To answer your question there are two steps:
(1) Figure out what HTML you want the browser to get.
(2) Write your JSP to produce that HTML.
You don't seem to have done step (1) properly. And then if you don't know what HTML you want to produce, it's hard to write code to produce it.
also store selected value in request and after when page loads back retrive both the values.
Implementing this in jsp using el or scriptlet would be better option than implementing this in java script due to following to reasons -
1- If java script is disabled in browser, this functionality would not work
2-it would require some additional data to be sent to the browser resulting in performance hit.
Paul Clapham wrote:From what I can see, at least from the original post, Thomas already has JSP code which generates the SELECT element. All that's needed is to improve that to add the "selected" attribute on the appropriate OPTION element. Perhaps the question is how to do that; I can see that being a FAQ. I know I had trouble figuring out a way to do that in the EL.
Exactly what I had in the mind, they must be some off you that may have create a Drowdown in which you select a value. submit the form.
And when they JSP is visible again with a result, the last selected value should be the one should as default selected in the dropdown.
So at least it is possible to what the result was based on.