my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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: 60800
    
  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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get default value to my dropdown list
 
Similar Threads
Comparing values using JSTL
Prepopulating a jsp
Dependant drop down list boxes in JSP page
iterating over hashmap using jstl
Mixing JSP and Scriptlets throws compilation errors