• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 67752
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 67752
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks a lot.. This is great help to me.
     
    Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic