• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default value in dropdown list after submitting page

 
Mike Himstead
Ranch Hand
Posts: 178
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting same problem
 
Dhanya Palanisamy
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • 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
  • 0
  • 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: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic