Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can the drop down menu remember the last selection?  RSS feed

 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all. Using JSP with HTML and new to it, so this question may be way too simple for y'all, but here goes:

I have a simple dropdown menu. The user selects one option and then clicks a button, and a table is displayed based on the selection. The user may then make another selection on that same menu, or filter the results in various ways.

What I'd like to be able to do is for the dropdown menu to reflect the last selection after the button is clicked (right now it shows the first option). I want this for various reasons--mostly because the user can then filter the original results and I'd like the user to be able to see their original selection after they do so.

I understand that, using javascript, I can populate the drop down fields in various ways. Is there any way to do this using just JSTL, without javascript? What I want is something like this:

But of course this doesn't work.

Any help (or pointers) would be very helpful...thanks in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JSP forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you need to use the correct HTML syntax, which would be to place the attribute:

selected='selected'

on the option that is to be selected.

And, to get you going on the JSTL aspect, here's a code snippet from a JSP where I load a select element from a list contained in scoped variable unitNumbers and with the currently selected value in the scoped variable trackedUnit.

This code assumes that the option value and the option text are one and the same. Things get more complicated if this is not true, but this should give you the general idea:


[ July 13, 2006: Message edited by: Bear Bibeault ]
 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. I'll have to play with this some...but that's what I needed--a pointing in some direction!

Thanks again. I'll let you know what I figure out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!