In a JSP,change in a combo box dynamically gets data from DB


Web tier: servlets, JSP, Web frameworks: In a JSP,change in a combo box dynamically gets data from DB

  1. 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 to do this? any body knows kindly reply me.. thanks.. vignesh mail me @ [email protected]
  2. 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,
  3. 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).
  4. 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
  5. 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
  6. 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