You are here: Re: Newbie to Javascript needs help with zip to city, county state page « PHP Language « IT news, forums, messages
Re: Newbie to Javascript needs help with zip to city, county state page

Posted by Tyrone Slothrop on 09/14/05 06:22

On Tue, 13 Sep 2005 08:03:38 -0700, Me <me@none.net> wrote:

>I'm using php and mysql for an "application" site for users at our clinic.
>The problem I'm having (and I have no clue how to do it) is that I'd like
>users to enter a zipcode into a field, then have that auto magically pop up
>the city, county and state of that zipcode (I don't have to worry about
>zipcodes in seoarate counties as we only need to use a database containing
>our local areas.)
>
>Right now I just have it set for users to manually enter zip, city, county
>and state, but some use all caps and some don't, some spell cities wrong,
>etc. I was thinking of making a mysql query in php, but that wouldn't
>refresh the current page, and I'd like the page to be one form (instead of
>using iframes and multiple forms they'd have to submit.) AJAX looks
>interesting, but I'm not very familiar with Javascript (if at all.)
>
>So, I'm hoping there is a script, or something similiar that I could use as
>a template, or at least learn from, where I could replace part of the code
>on the page so the user would only need to type in the zipcode to retrieve
>city, county and state information.
>
>Of course, after populating the fields with the correct information, the
>user could finish the form and submit it.
>
>It sounds like a simple thing (although I'm sure it isn't), but I'm not too
>familiar with Javascript, and I searched google and have yet to see it
>addressed (although I've seen similiar problems posted in various
>newsgroups.) Could someone just point me in the right direction? This
>newsgroup seemed to have pretty cool people from the posts I read, so I
>thought I'd look for help here. Thanks in advance.

Yes, it may sound simple... ;-)

I did something similar using a hidden iframe to do the search when a
value was entered in a form. The value of the field was sent to the
iframe with JavaScript and, after the query completed, the values for
fields were sent back to the form with JavaScript. I can tell you
that it is possible and that it will take a few hours to figure out
how to do it, especially if you are as illiterate as I with JS.

I am not going to post the code but, if you want help doing something
like this and get stuck, just post here to my attention. I will give
you a few hints though. When the zip code is entered into the form
field, do an onChange to call a function to update the iframe:
<input type="text" name="zip" value="" onChange="update(this.value)">

The JS function looks like:
update (zip) {
parent.iframename.document.location.href='iframe.html?'+zip;
}

When the iframe reloads, it plugs the query string into a query. The
results are then passed back to the form using JS:
parent.document.form.city.value="<?php echo $row['state']; ?>";

And, just as you are not Me, I am not Tyrone Slothrop but play him on
Usenet. ;-) (10 bonus points if you can name the book and the author
without googling the name.)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация