• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

populating a field automatically  RSS feed

 
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
 
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
 
Author and ninkuma
Marshal
Posts: 66826
168
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.
 
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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!