wood burning stoves*
The moose likes JSP and the fly likes How to get default value to my dropdown list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get default value to my dropdown list" Watch "How to get default value to my dropdown list" New topic
Author

How to get default value to my dropdown list

Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Hi I am using a Dropdownlist in my Jsp page. Values are coming form Table.

my problem is: the Last value(Harry) in the for loop is getting displayed as the default value in the dropdown list.
I want to dispaly (--Select one--) as the default value when page loads. How to do this?
my code goes here:


With Regards,
Anu
Shashank Ag
Ranch Hand

Joined: Dec 22, 2009
Posts: 88

You are generating selected="selected" in each line of code, that's the problem.
It should be only in first option.


SCJP 91%, SCWCD 97%
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Shashank Ag wrote:It should be only in first option.

Correction: it should only be on the option that is to be initially selected.

In cases like this, look at the HTML being sent to the browser. It would have shown you that your HTML is invalid.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get default value to my dropdown list
 
Similar Threads
Prepopulating a jsp
iterating over hashmap using jstl
Comparing values using JSTL
Mixing JSP and Scriptlets throws compilation errors
Dependant drop down list boxes in JSP page