| Author |
How to display only selected amount of data from database in two dropdown lists?
|
Pankti Desai
Greenhorn
Joined: Feb 10, 2012
Posts: 3
|
|
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
Joined: Jan 10, 2002
Posts: 56173
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Pankti Desai
Greenhorn
Joined: Feb 10, 2012
Posts: 3
|
|
|
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
Joined: Jan 10, 2002
Posts: 56173
|
|
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
Joined: Feb 10, 2012
Posts: 3
|
|
|
Thanks a lot.. This is great help to me.
|
 |
 |
|
|
subject: How to display only selected amount of data from database in two dropdown lists?
|
|
|