• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

JSP Drop Down List

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I mainitain the selected value from the dropdown list so when the jsp is redisplayed, the selected values are maintained (are shown) and not lost?



Michael J. Payne
Consultant
Fusion Alliance
Indianapolis, Indiana
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to generate appropriate HTML to indicate which records in the list are selected.
Basically for whichever option is selected, you have to have <option value="42" selected="true">

Frameworks like struts/JSF will often take care of this for you, otherwise you do it manually, with an if statement in the middle of your rendering the list.
Another approach is to render the list as usual, and then execute a javascript command onload which sets the value. It sometimes looks a bit neater in code ;-)
 
Sheriff
Posts: 67693
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
One caveat:

selected="true"

is probably a poor way to express this because it would lead one to believe that saying selected="false" would have the opposite effect.

In XHTML, if anything is supplied as a value to the selected attribute -- be it selected="true" or selected="false" or even selected="sdhsjhdsh" -- the option will be selected.

This is true of all attributes that have no value in HTML but must have a value in XHTML.

The standard means of expressing these is to repeat the name of the attribute. E.g. selected="selected".
[ October 19, 2006: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi...

just try this one...

<option value="1" selected>

this is sufficient... need not write select= "true"/false/anything else...
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok if you want the selected value in the page after refresh means again you are sending it to the same page yes..

simple

place in javascript as

lacation="pagename.jsp?&yourattribute=value"

simple
 
Bear Bibeault
Sheriff
Posts: 67693
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 toukhir mujawar:
need not write select= "true"/false/anything else...



Depends upon whether you are using HTML or XHTML. In the latter, the value is required.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic