Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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.



     
    Sheriff
    Posts: 67402
    173
    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
    Sheriff
    Posts: 67402
    173
    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.
     
    This one time, at bandcamp, I had relations with a tiny ad.
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic