Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute query in javascript function

Status
Not open for further replies.

fsqueeen

Programmer
Jul 8, 2002
43
0
0
MY
I'm doing a PHP + mysql application which will verify zip code on member form. I hope to do the verification on client side script, javascript.

Zip Code: <input text>
City: <input text>
State: <selection box> or <input text>

After user enter 5 digits zip code, javascript function is called and zip code is verified by querying zip code database. If zip code is wrong, error message prompt. Else, city and state will be returned and City and State are auto filled in the form.

I wonder if I can execute a query from javascript function? Or anyone have better idea on this question? Please help... thanks in advance!
 
Do a search on AJAX.
Javascript is client-side only and so cannot connect to a database to do the lookup for you but you can use AJAX to do a background call to another page that uses PHP or another server-side language to do the lookup and return the result to your Javascript function.

The usual way would be to submit the form, lookup the value and then redisplay the form re-populating all the field values which is a bit clunky.

Another alternative is to read all the zip code data in at the top of the page storing it in a Javascript array and when the person enters a zip code you search the array for a match without having to call an outside page to do the lookup.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top