Log in

View Full Version : Community website, zipcode text box



christianc2005
07-09-2008, 11:15 PM
Hi, I'm trying to create a community website, basically a database of peoples info, sorted by their zip codes.

What I need is a text box that the user will type their zip code and it takes them to the page for that zip code.

I'm pretty sure this is possible just don't know how... :confused:

Thanks. :)

rangana
07-09-2008, 11:59 PM
You might find this example useful:


<script type="text/javascript">
window.onload=function()
{
document.getElementById('go').onclick=function()
{
var dom='http://mysite.com/', // Set your web domain
inp=document.getElementById('inp'); // ID of textbox that accepts the zip code
if(inp.value.match(/(\d)/))
location.href=dom+inp.value+'.htm'; // If matches the regex, goes to domain plus [zip].htm
else{ // Else informs the user that should be numbers.
alert('Numbers please');
inp.value='';inp.focus();}}}
</script>
<label>Your Zip code:</label>
<input type="text" id="inp"><input type="button" value="Go" id="go">

christianc2005
07-10-2008, 12:34 AM
ok thanks I'll give it a try :)