• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get default value to my dropdown list

 
Anu satya
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Shashank Ag
Ranch Hand
Posts: 88
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are generating selected="selected" in each line of code, that's the problem.
It should be only in first option.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic