either or script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PC-Dad

    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

  • kaeli

    #2
    Re: either or script

    In article <1112979116.885 440.284070@g14g 2000cwa.googleg roups.com>,
    scott.solar@gma il.com enlightened us with...[color=blue]
    > 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?[/color]

    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.



    Comment

    • J Wynia

      #3
      Re: either or script

      PC-Dad wrote:[color=blue]
      > 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
      >[/color]

      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="JavaS cript">
      <!--
      function check_zip(){
      $zip = testform.zip.va lue;
      if(($zip == null) || ($zip == ""))
      {
      testform.action = "form_processor 1.php";
      } else {
      testform.action = "form_processor 2.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.

      Comment

      • Lee

        #4
        Re: either or script

        PC-Dad said:[color=blue]
        >
        >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?[/color]

        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.l ength;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="retur n false">
        Enter 5-digit U.S. zip code: <input name="zip"><br>
        <input type="button" value="test" onclick="redire ct(this.form.zi p.value)">
        </form>
        </html>

        Comment

        • otto

          #5
          Re: either or script

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

          Comment

          • Lee

            #6
            Re: either or script

            otto said:[color=blue]
            >
            >What about populating the list of zips from an xml file called through
            >XMLHttpRequest ? That would keep things client side.[/color]

            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.

            Comment

            • Randy Webb

              #7
              Re: either or script

              J Wynia wrote:[color=blue]
              > PC-Dad wrote:
              >[color=green]
              >> 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
              >>[/color]
              >
              > 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="JavaS cript">[/color]

              language attribute is deprecated, use the type attribute instead.
              [color=blue]
              > <!--[/color]

              Hiding scripts is an obsolete practice.
              [color=blue]
              > function check_zip(){
              > $zip = testform.zip.va lue;[/color]

              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;
              [color=blue]
              > if(($zip == null) || ($zip == ""))
              > {
              > testform.action = "form_processor 1.php";[/color]

              same here with the global-ness of testform.
              [color=blue]
              > } else {
              > testform.action = "form_processor 2.php";[/color]

              ditto.

              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

              Comment

              • otto

                #8
                Re: either or script


                Lee wrote:[color=blue]
                > otto said:[color=green]
                > >
                > >What about populating the list of zips from an xml file called[/color][/color]
                through[color=blue][color=green]
                > >XMLHttpRequest ? That would keep things client side.[/color]
                >
                > 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.[/color]

                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.

                Comment

                • PC-Dad

                  #9
                  Re: either or script

                  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

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: either or script

                    PC-Dad wrote:
                    [color=blue]
                    > 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?[/color]

                    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

                    Comment

                    Working...