473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

either or script

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
9 1209
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
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
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
What about populating the list of zips from an xml file called through
XMLHttpRequest? That would keep things client side.

Jul 23 '05 #5
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
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jon Thackray | last post by:
I'm trying to build some mathml for a paper. I've got the mathml2 dtd, and the style sheets also from the canonical website http://www.w3.org/Math/. But I'm having some trouble. I've input the...
4
by: dysfunctional | last post by:
Hi there, I'm a complete zero at javascript in need of a hero. I run a free, non-commercial site which includes a searchable database of hotels in Morocco. Find the page at...
5
by: Stephen | last post by:
Could someone please help me with some validation. I have to write code which checks to see whether a dropdown list is populated with a value or a checkbox is checked. I want the code to run on the...
3
by: mrwoopey | last post by:
Hi, I am using the example "Authenticate against the Active Directory by Using Forms Authentication and Visual Basic .NET": http://support.microsoft.com/default.aspx?scid=KB;EN-US;326340 ...
1
by: Kenneth Baltrinic | last post by:
Is there an easy way with a validation control to have either one field or another required but not both? This is for a forgotten password page where the user must fill in either a user ID or...
3
by: David Lozzi | last post by:
Error: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive at line 6 Line 4: <script RUNAT="SERVER"> Line 5: ...
2
by: gisleyt | last post by:
Is it possibly to specify that I want a either a element or an attribute to occur, but not both at the same time? <xs:complexType name="foo"> <xs:sequence> <xs:element minOccurs="0" ref="bar"/>...
6
by: MrTom | last post by:
Hello, I am displaying a the html for a web page in a frame on my web page. We only support IE and are only using Win XP or higher. That web page contains HREF entries for other url's. For...
1
vikas251074
by: vikas251074 | last post by:
Hello sir, I am facing some problem for which I am trying hard to solve it. But in vain. This programe is for View/Deletion. When I run program for first time, I select vlan from list and press...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.