• 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

Default value in dropdown list after submitting page

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a dropdown list that has no default value as of now. To make it more user friendly I added an empty value so the user doesn't accidentally makes a selection if he set another option available at that page.

The part in question now looks like this:


So every time one enters the page, the dropdown list is empty. Unfortunately, one minor detail is missing: if the user made a selection from the list and submitted the page, the list shows the previously chosen element from the list, not the (empty) default value. Did I make a mistake?

PS: sorry for the code mess.
[ December 21, 2006: Message edited by: Mike Himstead ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am getting same problem
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a tip :

http://www.interlacken.com/winnt/tips/tipshow.aspx?tip=49
 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dhanya,

thank you for your reply, but I'm confused by the link you provided: it describes a way to persist selection between page hits, I want to do the opposite. My current implementation keeps the previous selection in mind already.
 
Dhanya Palanisamy
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Mike, have a onchange event like this.
<select name="Drop" onchange="Drop()">
<option value="">
<option value="001">tom
<option value="002">dick
<option value="003">harry
</select>

and change the drop down value to default inside the function

<!--
function Drop() {
var form = document.forms[0];
form.Drop.option.selectedIndex.value=""; // not sure about the syntax
}


// -->
 
Sheriff
Posts: 67746
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
"Javaranch feeder",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Sheriff
Posts: 67746
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 Dhanya Palanisamy:
Sorry Mike, have a onchange event like this.



That makes no sense. You cannot assign a server-side method to a client-side event handler.

Since Mike is using Struts action to construct the control under question, I've moved this to the Struts forum.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't quite understand your question or the flow of your application. My guess is that you are storing the form in session (the default scope is session if you do not specify it on your action mapping). If that is the case...actually I almost never use session scoped forms so I don't know if it is best practices to clear the form in the form's reset method or in the action that is displaying the page.

- Brent
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if the user made a selection from the list and submitted the page, the list shows the previously chosen element from the list, not the (empty) default value.


This is exactly what is supposed to happen. Normally, if a user enters data on a form and you redisplay it for some reason, you want to show the user the data they entered, right?

Since the <html:select> tag is tied to the value of the property you specify, if you want to reset it, simply set the value of the property in your action class like this:

myform.setManagerId("");
 
reply
    Bookmark Topic Watch Topic
  • New Topic