File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes jsp + dropdown + automatically populate the vales from the db in the Text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp + dropdown + automatically populate the vales from the db in the Text box" Watch "jsp + dropdown + automatically populate the vales from the db in the Text box" New topic
Author

jsp + dropdown + automatically populate the vales from the db in the Text box

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1382
My dropdown has 3 values. Based on the selection of a particular value, the next 2 text box values should automatically (values are taken from the databse) displayed in the corresponding text boxes. How can i do that??
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
Onchange of the first dropdown list, submit the form, fetch the values from the database and generate the other two drop-downs with the values fetched from the database. You could pass ArrayLists from session attributes.


Cheers!<br /><b>Annie</b>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I've put together a demo app that does this with a mock database object.
http://simple.souther.us/not-so-simple.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Tien-Chih Wang
Greenhorn

Joined: Feb 23, 2003
Posts: 25
You can use Javascript, when choose the first drop-down, reload the page and then display the second one.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1382
Hi Ben Souther, i seen your sample DynamicSelectLists.war before posting this question. But i am not able to understand.
If you give small piece of sample code, that's better..
Without reloading/ submiting the page...is it possible ???
Bhaskar Rao
Greenhorn

Joined: Apr 25, 2005
Posts: 23
Hi,
If you dont want reloading the page, then you have to go for JavaScript and fetch all the data necessary to populate the textbox before the JSP is loaded.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by kri shan:
Hi Ben Souther, i seen your sample DynamicSelectLists.war before posting this question. But i am not able to understand.
If you give small piece of sample code, that's better..
Without reloading/ submiting the page...is it possible ???


It is possible to do this without reloading the page.
As JsBhaskar said, you would do this with Javascript code, not server side Java. Also, you would have to load all the possible information into the page when it is first drawn. For small amounts of data, this is fine.

There is a forum for HTML/Javascript on this site:
http://www.coderanch.com/forums/f-20/HTML-JavaScript
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

Another, somewhat advanced, possibility is to use the XmlHttpRequest Javascript object to send a "behind the scenes" request to the server without having to refresh the page. This is an elegant solution, but requires a good grasp of the principles involved.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp + dropdown + automatically populate the vales from the db in the Text box