Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Show or Hide contents based on dropdown selection

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a dropdown with seven items. Based on the item I choose, I want it to show specific content. But, currently, it's showing everything - all seven items contents.

How do I choose an item and show only specific content?
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is of no use to you for this; you need to use JavaScript.

As such, I have moved this to the HTML/JavaScript forum.

Please read this article to understand what JSP is and why it cannot be used for dealing with things like this.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to establish an event handler for the change event of the select handler, and then in the handler affect the CSS of the elements that you wish to show and hide.

Using jQuery with your JavaScript makes this almost trivial.
 
Kaiser Rahman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you have an example of to do this with JavaScript and JQuery?

I understand this isn't JSP centric. JavaScript/JQuery nsolution would suffice.

 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You first -- give the code a try and we can help you with it from there.
 
Kaiser Rahman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you have a lot of redundant code there. Factor it down to only that which is necessary.

Also, never put a ready hander inside another ready handler. And you have two different syntax's for ready handlers; that's bad form -- pick one syntax and stick with it. Otherwise it just confuses people reading your code.
 
Kaiser Rahman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is how do I assign certain DIV area to a Javascript variable?
 
Kaiser Rahman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I assign DIV ID to a Javascript variable like $('#divID=1').show();
 
Kaiser Rahman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's the JavaScript forum I can post this? Anybody knows?
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic