• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pankti Desai
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.



     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64959
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 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
    Author and ninkuma
    Marshal
    Pie
    Posts: 64959
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic