View Full Version : Location list sort

12-06-2010, 08:26 PM
We list our branches on our webpage, but I want people to be able to search for the nearest ones.

This is the form I built as a place holder... but I'm sure I need a "little something" to go along with it. ha ha ha.

<form class="login">
&nbsp <label class="white"><b>Zip Code</b><br />
&nbsp <input name="zip" type="text" maxlength="5" size="10"/>

<br /><br />


&nbsp <input type="submit" name="submit" id="submit" value="Go!" class="btn" />

I would like to sort them in order of closest to furthest (or even just display the top 5)... where would I find something like that?

I seem to be having a difficult time with my searches in google and otherwise.

Anyone have any ideas?

Old Pedant
12-06-2010, 08:53 PM
Not a task for JavaScript. Needs to be done server-side.

Possible exception: If you only have a handful of branches and you only have a relatively few zip codes you care about people entering (that is, if you only have branches in Connecticut and you don't allow zip codes outside that state), you *could* then do it in JS coding.

But in general, getting distance and/or nearest location based on zip code is best left to server-side processing. It's almost always done via a database query.

Old Pedant
12-06-2010, 08:55 PM
Here's an example demo I put together a few years back, using ASP server-side code:

It just shows all zip codes close to a given zip code, but would be easy to adapt to stores/branches close to a given zip, instead.