This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default value in dropdown list after submitting page

 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • 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 ]
 
JavaRanch feeder
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting same problem
 
Dhanya Palanisamy
Ranch Hand
Posts: 61
 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • 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
  • 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
}


// -->
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • 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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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("");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic