Discussions
Web tier: servlets, JSP, Web frameworks: In a JSP,change in a combo box dynamically gets data from DB
-
In a JSP,change in a combo box dynamically gets data from DB (5 messages)
- Posted by: vignesh kumar
- Posted on: November 26 2006 07:04 EST
In a JSP page there are 2 combo boxes.Change in one combo box will have hit the database & get values from that & populate in the next combo box.There is no submit buttons.how to do this? any body knows kindly reply me.. thanks.. vignesh mail me @ [email protected]Threaded Messages (5)
- Re: In a JSP,change in a combo box dynamically gets data from DB by arijit dey on November 26 2006 23:23 EST
- Re: In a JSP,change in a combo box dynamically gets data from DB by Sergiu Burian on November 27 2006 12:41 EST
- Re: In a JSP,change in a combo box dynamically gets data from DB by Kit Davies on November 28 2006 11:33 EST
- Re: In a JSP,change in a combo box dynamically gets data from DB by Sergiu Burian on November 28 2006 17:07 EST
- Re: In a JSP,change in a combo box dynamically gets data from DB by Krishna Prasad on November 30 2006 09:31 EST
- Re: In a JSP,change in a combo box dynamically gets data from DB by Sergiu Burian on November 28 2006 17:07 EST
-
Re: In a JSP,change in a combo box dynamically gets data from DB[ Go to top ]
- Posted by: arijit dey
- Posted on: November 26 2006 23:23 EST
- in response to vignesh kumar
Well! You have the combobox, on selection you can specify to refresh the page, all you need to have a javascript which will be called on onSelect and you do your stuff in teh javascript function and submit the page which will have the same page as target, so you will refresh the page. cheers, http://www.javaicillusion.blogspot.com/ -
Re: In a JSP,change in a combo box dynamically gets data from DB[ Go to top ]
- Posted by: Sergiu Burian
- Posted on: November 27 2006 12:41 EST
- in response to arijit dey
Hi ! Or even cooler than submitting the whole page: Use AJAX. Write an onSelect javascript handler for the first combobox, whose implementation gets the XMLHttpRequest and sends this request to your (special) servlet that should be able to build JUST the HTML of the second combobox. The result HTML is accessible in your javascript code so that you can set it as the HTML content of the DIV containing the second combobox. Please note that you can even do this asynchronously, by marking the XMLHttpRequest as asynchronous and registering a javascript method as a callback handler (this method would then fill the second combobox). -
Re: In a JSP,change in a combo box dynamically gets data from DB[ Go to top ]
- Posted by: Kit Davies
- Posted on: November 28 2006 11:33 EST
- in response to vignesh kumar
It depends on how much data you have. If it is a large amount, then using the previously suggested methods would work fine. I have done this in the past for small data sets by building a table of values (ie. [[combo1,combo2],[combo1,combo2], etc]) in javascript when the page was being built, then using javascript to change the combo box values in the browser in response to the users selections. HTH Kit -
Re: In a JSP,change in a combo box dynamically gets data from DB[ Go to top ]
- Posted by: Sergiu Burian
- Posted on: November 28 2006 17:07 EST
- in response to Kit Davies
Hi again, just wanted to point out that I have suggested the AJAX solution because of the other pot from Vignesh : Calling a java function from a javascript function in a JSP page ;) Cheers, Sergiu -
Re: In a JSP,change in a combo box dynamically gets data from DB[ Go to top ]
- Posted by: Krishna Prasad
- Posted on: November 30 2006 09:31 EST
- in response to Sergiu Burian
AJAX is a good solution. But, in normal application no one wants to make application complex. Use AJAX, if your application is already exposed to AJAX. Or, just a java script will do the trick. You get ton's of information on "how to call Java method from javascript" if you search in Google! Take a best pick and apply your thought, you'll get the expected!! :) Krish