Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SELECT list in forms  RSS feed

 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help!BACKGROUND
==========
I have the SELECT item below in a form.
<select name="COptions" >
<option value="COURSE OPTI0N 1" selected>COURSE OPTI0N 1</option>
<option value="COURSE OPTI0N 2">COURSE OPTI0N 2</option>
<option value="COURSE OPTI0N 3">COURSE OPTI0N 3</option>
<option value="COURSE OPTI0N 4">COURSE OPTI0N 4</option>
</select>


OBJECTIVE
=========
I want the option that the user selected before submission to remain selected after submission. Presently after submission, the SELECT field is auto set back to its default option

Note: I do not want to use Javascript for this.
[ January 19, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not metnion what you are submitting to, or how you are getting back to the page. Without such details, no targetted advice is possible.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your 'question'.

NOTE: The option item is the only item in my form.

I am submitting to an XML file. To put it another way, when my form is submitted, it gets data from an XML file. The value selected in the OPTION is the criteria.

I get the data in the XML file with a scriptlet, then I use
<%= BbanbOpValueBean.getSpeed() %> for displaying each returned value

Here is the code for getting the data:
<%
Utils utils = new Utils();
String OptionSelected = request.getParameter("Options");
String otherCompsOptionSelected = request.getParameter("otherCompsOptions");

if (OptionSelected == null || OptionSelected.length() < 1){OptionSelected = "Broadband Option 1";}
if (otherCompsOptionSelected == null || otherCompsOptionSelected.length() < 1){otherCompsOptionSelected = "AOL Silver";}

BroadbandOptionBean BbanbOpValueBean = utils.getOptionValues( OptionSelected );
BroadbandOptionBean otherCompsOpValueBean = utils.getOptionValues( otherCompsOptionSelected );
%>



Thanks for your help.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dele Oke:

I am submitting to an XML file.


XML is not an active server technology.

What is your form being submitted to for processing? A CGI script? Another JSP page? The same JSP page? A servlet?
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is being submitted to "The same JSP page" i.e. itself:
<form action="switcher.jsp" method="post">

The name the form is switcher.jsp.

Thank you.

Ola Oke.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dele Oke:
It is being submitted to "The same JSP page" i.e. itself:


In that case the request parameter denoting what the selection was is readily available. You can use that to set the selected attribute on the select option that matches the submitted value.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please please send me a line of code that actually does this or a link to a site has an example.

I store the parameter value in a temp variable like this:
<% String OptionSelected = request.getParameter("Options"); %>

But I do not know the excact code to use for setting the select list to the value of <%= OptionSelected %>


Thank you very much.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If statements are not that hard to figure out.

Since I see you are using scriplets in your pages (cringe) here's a snippet to get you atarted.



Note that I changed OptionSelected to optionSelected. Please become familiar with accepted Java naming conventions. It makes your code surprisingly hard to read when you don't follow the conventions.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I will not try it out. Also thanks for the advise
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!