By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,624 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,624 IT Pros & Developers. It's quick & easy.

either or script

P: n/a
I'd like to make a form in which the user would input her zip code.
When they submit then the script would compare to the list of zips that
I service. If their zip is included re-direct to page A or if not
included re-direct to page B.

Would anyone be able to assist me here?

Thanks;

Scott Solar is
PC-Dad.com

Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
In article <11**********************@g14g2000cwa.googlegroups .com>,
sc*********@gmail.com enlightened us with...
I'd like to make a form in which the user would input her zip code.
When they submit then the script would compare to the list of zips that
I service. If their zip is included re-direct to page A or if not
included re-direct to page B.

Would anyone be able to assist me here?


This is best done on the server-side.
Is this jscript and .net?
If not, this group is not really the appropriate place for it, but I might be
able to help you. What scripting language are you using on the server?

--
--
~kaeli~
Experience is something you don't get until just after you
need it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
PC-Dad wrote:
I'd like to make a form in which the user would input her zip code.
When they submit then the script would compare to the list of zips that
I service. If their zip is included re-direct to page A or if not
included re-direct to page B.

Would anyone be able to assist me here?

Thanks;

Scott Solar is
PC-Dad.com


Here's a sample HTML document that switches the form's "action" to a
different page if the "zip" field is filled in. You can modify this
greatly to do whatever you want by changing the stuff in the condition
part of the "if" statement. Of course, once you get more than a few
conditions, you'll need something more complex than the if, but this
will work for most basic cases.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language="JavaScript">
<!--
function check_zip(){
$zip = testform.zip.value;
if(($zip == null) || ($zip == ""))
{
testform.action = "form_processor1.php";
} else {
testform.action = "form_processor2.php";
}
}
//-->
</script>
</head>

<body>
<form name="testform" onsubmit="check_zip();" action="">
<input type="text" name="address">
<input type="text" name="zip">
<input type="submit">
</form>
</body>
</html>
J Wynia
Myriad Intellect, Inc.
www.myriadintellect.com
Jul 23 '05 #3

P: n/a
Lee
PC-Dad said:

I'd like to make a form in which the user would input her zip code.
When they submit then the script would compare to the list of zips that
I service. If their zip is included re-direct to page A or if not
included re-direct to page B.

Would anyone be able to assist me here?


It would probably be better to do that on the server side, if possible,
because you wouldn't have any practical limit to the number of zip codes
or other factors that you use to decide which page to show.

Here's one example that allows you to use an "x" as a wildcard character
and number options in square brackets. The entry "8080[79]" matches
either a 7 or a 9 in the last position. "876x[123]" would match any digit
in the 4th position, and any of 1, 2, or 3 in the 5th, etc.

Note that any invalid entry is treated as a zip code that isn't in the
area.

<html>
<head>
<script type="text/javascript">

zipList= [ "12345", "23456", "345xx", "4567x",
"56789", "56780", "8080[79]", "7xx01"
];

function inArea(zip) {
for(var i=0;i<zipList.length;i++) {
if ((new RegExp("^\\s*"
+zipList[i].replace(/x/g,"\\d")
+"\\s*$").test(zip))) {
return true;
}
}
return false;
}
function redirect(zip) {
if(inArea(zip)) {
location="http://www.google.com";
} else {
location="http://maps.google.com/maps?q="+zip+"&spn=0.1,0.1";
}
}
</script>
</head>
<body>
<form onsubmit="return false">
Enter 5-digit U.S. zip code: <input name="zip"><br>
<input type="button" value="test" onclick="redirect(this.form.zip.value)">
</form>
</html>

Jul 23 '05 #4

P: n/a
What about populating the list of zips from an xml file called through
XMLHttpRequest? That would keep things client side.

Jul 23 '05 #5

P: n/a
Lee
otto said:

What about populating the list of zips from an xml file called through
XMLHttpRequest? That would keep things client side.


I'm not sure what advantage you're suggesting.
In both cases, the data is sent from the server to the client.
In the case of XML, the data is in a more verbose format, but
it might be easier to import into a database in the future.

Jul 23 '05 #6

P: n/a
J Wynia wrote:
PC-Dad wrote:
I'd like to make a form in which the user would input her zip code.
When they submit then the script would compare to the list of zips that
I service. If their zip is included re-direct to page A or if not
included re-direct to page B.

Would anyone be able to assist me here?

Thanks;

Scott Solar is
PC-Dad.com

Here's a sample HTML document that switches the form's "action" to a
different page if the "zip" field is filled in. You can modify this
greatly to do whatever you want by changing the stuff in the condition
part of the "if" statement. Of course, once you get more than a few
conditions, you'll need something more complex than the if, but this
will work for most basic cases.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language="JavaScript">


language attribute is deprecated, use the type attribute instead.
<!--
Hiding scripts is an obsolete practice.
function check_zip(){
$zip = testform.zip.value;
There is very good reason why you do not see that shortcut notation very
often in this newsgroup. IE creates a global scope to the form object
that is neamed testform, no other browser (AFAIK) do that. So the above
line would be more cross-browser as:

document.forms['testform'].elements['zip'].value;
if(($zip == null) || ($zip == ""))
{
testform.action = "form_processor1.php";
same here with the global-ness of testform.
} else {
testform.action = "form_processor2.php";


ditto.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #7

P: n/a

Lee wrote:
otto said:

What about populating the list of zips from an xml file called throughXMLHttpRequest? That would keep things client side.


I'm not sure what advantage you're suggesting.
In both cases, the data is sent from the server to the client.
In the case of XML, the data is in a more verbose format, but
it might be easier to import into a database in the future.


Just the advantage of keeping data separate from logic. You make a good
point either way the data has to be downloaded. I was assuming we were
talking about hundreds or thousands of numbers. In which case it may be
beneficial to download the data using XMLHttpRequest as a seperate
asynchronous http request. That way the user wouldn't have to wait
forever for the interface to download. The interface would download
first and then the data would download while the user is busy filling
out the form. Just an idea.

Jul 23 '05 #8

P: n/a
Thanks to everyone!

This is what I needed. I do home compueter repairs and such but may be
marketing other services outside of my home range. The zips I service
will get the current pages but outside my reach they can still buy my
other stuff.

Thanks again t everyone who helped.

Be strong and proser.

Scott Solar is PC-Dad.com

Jul 23 '05 #9

P: n/a
PC-Dad wrote:
I'd like to make a form in which the user would input her zip code.
When they submit then the script would compare to the list of zips
that I service. If their zip is included re-direct to page A or if
not included re-direct to page B.

Would anyone be able to assist me here?


Yes.

We had the ZIP code issue previously. All you have to do is create two
RegExps or objects and redirect accordingly. Be sure to include a
server-side alternative in case client-side scripting is unsupported.
PointedEars
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.