This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 60752
    
  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
Comparing values using JSTL
Dependant drop down list boxes in JSP page
iterating over hashmap using jstl
Mixing JSP and Scriptlets throws compilation errors