File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP 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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
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: 61413
    
  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: 61413
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default value in dropdown list after submitting page