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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zipcode to County help

Status
Not open for further replies.

dpwsmw

MIS
Apr 2, 2003
76
US
I am new to Java, so I was wondering, If I have a form that someone inputs the Zipcode in one field that it can autofill the other with the county, this is for a small number of counties and like 20 ZipCodes. So is it like an if then statement.

I would appreciate any help with this. thanks
 
well, if you mean JavaScript, then we can help. Java is something different entirely.

you can try something like this:

Code:
<script type="text/javascript"><!--

// array of zip codes 
var zc = new Array(11545, 06513, 06514, 11542);

// array of towns
var cc = new Array('Glen Head', 'East Haven', 'Hamden', 'Glen Cove');

function fill() {
    // get zip code field
    var zo = document.forms['f'].elements['z'];

    // get town field
    var co = document.forms['f'].elements['c'];
    
    // loop through zip codes
    for ( var i = 0; i < zc.length; i++ ) {
        if ( zc[i] == zo.value ) {
            co.value = cc[i];
            return;
        }
    }
}

//--></script>

<form name="f">
    <input type="text" name="z" onchange="fill();" />
    <input type="text" name="c" />
</form>

this isn't a very complete method of course, you'll need to change it to suit your needs. it should get you started though.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top