This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 66684
167
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)
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!