Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Populating a dependant select list without reloading the page  RSS feed

 
Vanessa Danin
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP which includes 2 select lists. The option selected from the first select list determines which set of options is displayed in the second select list.

The first select list always consists of the same, few options whereas the second select list's options may be numerous and importantly, are dynamic not only in terms of option list dependancy on the first select list but also because the values that make up each possible set of option values for the second select list are based on editable database values and therefore may change.

Currently, when I select an option from the first select list, I submit and reload the page to send through the selected option as a request parameter and use it to set a pageContext attribute in the reloaded page. I then test this pageContext attribute against several 'if' conditions to identify which is the correct set of options to display for the second select list. Then, I iterate through the set of values of the session-scoped attribute which applies to the matched 'if' condition. The session-scoped attribute holds a set of values retrieved from the database which are finally written out to the page as the second select list's option values.

My question is this: is there a way to display the relevant options for the second select list without reloading the page?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only way is with JavaScript by loading all of the options for the second Dropdown into arrays. If you are talking about tons and tons and tons of options then it will cause your page loading time to increase.

More info: see http://www.www.JavaScriptkit.com for double combo scripts.

Eric
 
Vanessa Danin
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for your reply Eric. Yes, I had decided against using Javascript arrays for that reason. I was hoping that there was another alternative but as there does not appear to be one I will continue using my existing code. Thanks once again for taking the time to assist me in making my decision.
 
Daniel Hedrick
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to send anyone away from Javaranch, but I recently came across this very useful tidbit that I think might be useful if you have a considerable amount of data to shuffle about:

http://developer.apple.com/internet/webcontent/iframe.html

Good luck!

-daniel
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the HTML/Javascript forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!