Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Newbie to Javascript needs help with zip to city county state page
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 15th December 16:00
me
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county state page



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.
  Reply With Quote


  sponsored links


2 15th December 16:09
tyrone slothrop
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county state page



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.do***ent.location.href='iframe.h tml?'+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.do***ent.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.)
  Reply With Quote
3 15th December 16:16
skadop
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county state page




Thanks for the heads up. Sorry for the bum email, I just got this 40tude
client and rushed through the process. Should post the right one now.

Anyhow, it looks like I got myself into something more than I wanted to,
but I may soldier on (apparently "franken-coding" will only get you so
far.)

I'll post the code as I "invent" some. Thanks again, Tyrone.
  Reply With Quote
4 15th December 16:26
frank [god]
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county statepage


I guess I need to know what your form does when submitted. Because I
think your best bet would be to do the lookup behind the scenes after
the user submits. Have a seperate table with all the zips, city, county,
states and when user submits, do a SELECT on that table and then do what
you need to do with it's results... ie add to database with other form
fields, or return to the screen the results and the the other form fields.
Hope this helps.
Frank
  Reply With Quote
5 15th December 16:40
skadop
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county state page


Here is what the code looks like in php now:
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> ADDRESS : </b> </td>
<td> <input type="text" name="thisADDRESSField" size="20" value="">
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> CITY : </b> </td>
<td> <input type="text" name="thisCITYField" size="20" value="">
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> STATE : </b> </td>
<td>

<? $result = mysql_query('SELECT STATE FROM LOCALSTATE');
$dropdown = '<select name="thisSTATEField">';

while ($row = mysql_fetch_array($result)) {
$dropdown .= '<option>'; $dropdown .= $row['0'];
$dropdown .= '</option>'; }
$dropdown .= '</select>';
echo $dropdown; ?>
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> COUNTY : </b> </td>
<td>

<? $result = mysql_query('SELECT COUNTY FROM COUNTY');
$dropdown = '<select name="thisCOUNTYField">';

while ($row = mysql_fetch_array($result)) {
$dropdown .= '<option>'; $dropdown .= $row['0'];
$dropdown .= '</option>'; }
$dropdown .= '</select>';
echo $dropdown; ?>
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> ZIP : </b> </td>
<td> <input type="text" name="thisZIPField" size="6" value=""
onKeyDown="javascript:return dFilter (event.keyCode, this, '#####');">
</td>
</tr>

Instead of using text inputs and select boxes for users, I wanted them to
be able to just enter a zipcode in the zipcode field and it would
automatically populate the city, county and state on the same page. Then,
ater the users finished filling out the rest of the form, they would just
submit it (and it would be entered into a mysql database.)

The form is done, however I wanted to change it to accomodate the
zipcode/autopopulated fields thing.

Just a side note: I am using some javascript for input masking, but it was
taken from Javascript source and was pretty easy to set up, don't think for
a moment I'm actually familiar with javascript.


  Reply With Quote
6 15th December 16:43
tyrone slothrop
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county state page


It happens to me all of the time. However, challenges help us get
better at what we do.
  Reply With Quote
7 15th December 17:35
frank [god]
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county statepage


I don't think you understand what I mean. Why have the fields
auto-populate when the user is not going to change them. Is it nessesary
for the user to know the city/state/county before submitting? If not, do
what I said, accept the zip from the user and do the insert into your
database with the relevant info from a select on a table with the
zip->city/state/county info. Understand?

Frank
  Reply With Quote
8 18th December 09:05
skadop
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county state page




Thanks for the heads up. Sorry for the bum email, I just got this 40tude
client and rushed through the process. Should post the right one now.

Anyhow, it looks like I got myself into something more than I wanted to,
but I may soldier on (apparently "franken-coding" will only get you so
far.)

I'll post the code as I "invent" some. Thanks again, Tyrone.
  Reply With Quote
9 18th December 09:15
frank [god]
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county statepage


I guess I need to know what your form does when submitted. Because I
think your best bet would be to do the lookup behind the scenes after
the user submits. Have a seperate table with all the zips, city, county,
states and when user submits, do a SELECT on that table and then do what
you need to do with it's results... ie add to database with other form
fields, or return to the screen the results and the the other form fields.
Hope this helps.
Frank
  Reply With Quote
10 18th December 09:29
skadop
External User
 
Posts: 1
Default Newbie to Javascript needs help with zip to city, county state page


Here is what the code looks like in php now:
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> ADDRESS : </b> </td>
<td> <input type="text" name="thisADDRESSField" size="20" value="">
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> CITY : </b> </td>
<td> <input type="text" name="thisCITYField" size="20" value="">
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> STATE : </b> </td>
<td>

<? $result = mysql_query('SELECT STATE FROM LOCALSTATE');
$dropdown = '<select name="thisSTATEField">';

while ($row = mysql_fetch_array($result)) {
$dropdown .= '<option>'; $dropdown .= $row['0'];
$dropdown .= '</option>'; }
$dropdown .= '</select>';
echo $dropdown; ?>
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> COUNTY : </b> </td>
<td>

<? $result = mysql_query('SELECT COUNTY FROM COUNTY');
$dropdown = '<select name="thisCOUNTYField">';

while ($row = mysql_fetch_array($result)) {
$dropdown .= '<option>'; $dropdown .= $row['0'];
$dropdown .= '</option>'; }
$dropdown .= '</select>';
echo $dropdown; ?>
</td>
</tr>
<tr valign="top" height="20">
<td align="right"> <b> ZIP : </b> </td>
<td> <input type="text" name="thisZIPField" size="6" value=""
onKeyDown="javascript:return dFilter (event.keyCode, this, '#####');">
</td>
</tr>

Instead of using text inputs and select boxes for users, I wanted them to
be able to just enter a zipcode in the zipcode field and it would
automatically populate the city, county and state on the same page. Then,
ater the users finished filling out the rest of the form, they would just
submit it (and it would be entered into a mysql database.)

The form is done, however I wanted to change it to accomodate the
zipcode/autopopulated fields thing.

Just a side note: I am using some javascript for input masking, but it was
taken from Javascript source and was pretty easy to set up, don't think for
a moment I'm actually familiar with javascript.


  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666