Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

selected attribute not working for dynamic dropdown list for a field to remain selected after submit  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP Page which accepts 4 fields. First field is populated by querying database as "Select Distinct field1 from db.table". After the user selects first field, onchange event causes field2 to be populated by querying the browser as "Select Distinct field2 from db.table where field1='"+value+"' ".

Same happens with 3rd and 4th fields. Now, when user submits the form, all fields get reset. I want the JSP page to show user selected values in all 4 fields.

If list in each dropdown is static (not dependant on other fields), then it works by using selected attribute. But this dependancy of each field on previous one is making it difficult.

Below code shows the user selected value after form submission for field1:

But for subsequent fields, onChange() event doesn't work, because we are not changing anything in field1.

I tried onLoad() to execute Javascript functions, but that doesn't seem to work.

How can we solve this???
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!