PDA

View Full Version : Database and JavaScript (for zip code)


stevenj_3
06-25-2001, 03:15 PM
I'm creating a form that would capture people's zip code addresses and redirect them based on the users input (i.e. If I typed in 20187, I would get a page specific to that zip code). I have a list of fifty zip codes that would be recognizable by the script and if the user inputs any zip code other than the fifty he/she will get an error page. Is this possible using Javascript? If so does anybody have any ideas? Thanks,
steve

Dave Swift
06-25-2001, 03:28 PM
I'm pretty sure that you cannot incorporate a *database* into CSS. But there may be other ways to do what you want with CSS, except without using a database.

Dr. Web
06-25-2001, 03:42 PM
only 50 zip codes? Thats not nearly enough for the US, but yes you can do it. Are you calling your zips from a database?

stevenj_3
06-25-2001, 04:14 PM
I didn't plan on using a database.

stevenj_3
06-26-2001, 04:21 PM
My goal was to use simple if then statements but I'm having trouble in assembling this script. Does anybody have any suggestions. The script should basically do this.

1. User types in zip code.
2. If zip code has a store associated with it then it displays the proper store page.
3. If the zip code doesn't have a store associated with it, then it goes to a default page.

Thanks folks!

Dr. Web
06-27-2001, 01:38 AM
This should work for you.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language=javascript>
function check(zip){
switch (zip){
case "80221":
document.location="http://yahoo.com";
break;
case "80234":
document.location="http://www.webcrawler.com";
break;
case "80237":
document.location="http://www.denver.com";
break;
default:
document.location="http://www.eye4u.com";
}
}
</script>
</head>
<body>
<form name=form1>
<input type=text size=5 maxlength=5 name=zip>
&nbsp;
<input type=button name=button1 value=GO! onClick="check(document.form1.zip.value);">
</form>
</body>
</html>