• Post Reply Bookmark Topic Watch Topic
  • New Topic

populating a field automatically

 
Pal Bonds
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an address page where I want to be able to populate the city field when a user enters a zipcode. what is the best way to do this. Keep in mind that I have to query a db when I get the zipcode to retrieve the city
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about having your JSP page submit to a servlet when a "Verify Zip Code" button is pressed? The servlet could then use JDBC, or a similar technology, to look up the zip code in the database. If found, it would store the corresponding city in the session context and forward the request to your JSP. Your JSP would then serve the page with the City field filled in.

Jules
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it would store the corresponding city in the session context


I would add that unless this value needs to have a lifetime well beyond the current page, storing the value in the request context would be preferred.
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick thought...you could probably use a little javascript to kick off the server-side call when they exit the field rather than making them click a button. Might be a slightly better user experience.

(ideally, use javascript to make sure the zip code field has 5 or 9 digits in it before calling the server at all, otherwise you'll annoy people who tab out of the field without entering anything)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!