aspose file tools*
The moose likes Struts and the fly likes Default value in dropdown list after submitting page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Default value in dropdown list after submitting page" Watch "Default value in dropdown list after submitting page" New topic
Author

Default value in dropdown list after submitting page

Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
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 ]
JavaRanch feeder
Greenhorn

Joined: Dec 22, 2006
Posts: 3
i am getting same problem
Dhanya Palanisamy
Ranch Hand

Joined: Oct 20, 2006
Posts: 61
Here is a tip :

http://www.interlacken.com/winnt/tips/tipshow.aspx?tip=49
Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
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

Joined: Oct 20, 2006
Posts: 61
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
}


// -->
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

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.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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("");


Merrill
Consultant, Sima Solutions
 
 
subject: Default value in dropdown list after submitting page