This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

How to display only selected amount of data from database in two dropdown lists?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am making a program in jsp servlet. There are three tables in database:
category , subcategory and items.
Their structure is like this ::
category 'A'
  • subcategory '1'

  • ===>item 'i'
    ===>item 'ii'
    ===>item 'iii'

  • subcategory '2'

  • ===>item 'iv'

    category 'B'
  • subcategory '3'

  • ===>item 'v'
    ===>item 'vi'

  • subcategory '4'

  • ===>item 'vii'

    category 'C'
    .....

    and so on.
    I want to place 2 dropdown lists :: one which shows only category names n another
    showing subcategory names..
    the problem is, in subcategory dropdown i want only subcategories of the category i have
    selected in first dropdown.
    Example :: if i select category 'A' i want that second dropdown should display only
    subcategory '1' and '2'.
    any help regarding this will be appreciated.
    Below is the code i have used for displaying category and subcategory dropdown in jsp page. but here
    all subcategories are displayed irrespective of which category name i have selected.



     
    Marshal
    Posts: 67336
    171
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    First of all, modern JSPs should not contain any Java code or scriptlets. That's a bad practice that's been discredited since the introduction of the JSTL and EL with JSP 2.0 10 years ago!

    Secondly, because you have no way of knowing what the user will choose until after the page has been delivered to the browser, this isn't something you'll be able to use just JSP for. This will also require JavaScript and Ajax to accomplish.
     
    Pankti Desai
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for your reply.. But do you have any idea on using ajax here?? mean what code should i use in ajax to display this??
     
    Bear Bibeault
    Marshal
    Posts: 67336
    171
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Google for "cascading dropdowns". It's practically the poster child for Ajax examples.

    And if you plan to use jQuery to help you with the JavaScript and Ajax (and you should because Ajax is tricky and verbose to write without it), you can download (for free) the sample code from my jQuery book here.

    The examples for chapter 8 shows how to create cascading drop downs easily using Ajax, JavaScript and JSP.
     
    Pankti Desai
    Greenhorn
    Posts: 3
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks a lot.. This is great help to me.
     
    Your mind is under my control .... your will is now mine .... read this tiny ad
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!