• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SELECT list in forms

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, I will not try it out. Also thanks for the advise
 
reply
    Bookmark Topic Watch Topic
  • New Topic