|
Posted by skadop on 09/14/05 18:00
On Wed, 14 Sep 2005 06:33:27 GMT, Frank [GOD] wrote:
> 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
>
>
> Me 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.
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.
;)
Navigation:
[Reply to this message]
|