• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've put together a demo app that does this with a mock database object.
http://simple.souther.us/not-so-simple.html
 
Tien-Chih Wang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Javascript, when choose the first drop-down, reload the page and then display the second one.
 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic