still hoping for a little help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Cox

    still hoping for a little help!

    Hello

    I cannot see why this is not working - the idea being to check the
    email address entered and if OK to move to either one of 2 pages - the
    move does not happen.

    The code below is in the lower of 2 frames.

    Why?!

    Cheers

    Geoff


    function getNextPage(){
    var num = Math.random();
    if (num<.5) {
    location.href=" group1/group1-lab1.htm";
    } else {
    location.href=" group2/group2-lab1.htm";
    }
    }

    function validateEmail ( emailField, errorMsg ) {
    emailpat =
    /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
    if( !emailpat.test( emailField.valu e ) ) {
    alert( errorMsg);
    emailField.focu s();
    emailField.sele ct();
    return false;
    } else {
    getNextPage();
    }
    }

    //-->
    </script>

    </head>

    <body>

    <h2>test</h2>

    <form name="emailForm " onsubmit="valid ateEmail( this.email , 'Please
    enter a valid email address')">
    Please enter your email address <input type="text" name="email">
    <input type="submit" value="enter">
    </form>
  • Stevo

    #2
    Re: still hoping for a little help!

    Geoff Cox wrote:
    I cannot see why this is not working - the idea being to check the
    email address entered and if OK to move to either one of 2 pages - the
    move does not happen.
    The simplest way to find out is to add alerts throught. That shows the
    path the code is taking, and if you alert the values of things too,
    it'll show you why. Example:

    function getNextPage(){
    var num = Math.random();
    alert("in getNextPage, random num="+num);
    if (num<.5) {
    alert("in getNextPage, following<.5 logic")
    location.href=" group1/group1-lab1.htm";
    } else {
    alert("in getNextPage, following else logic")
    location.href=" group2/group2-lab1.htm";
    }
    }

    Comment

    • Geoff Cox

      #3
      Re: still hoping for a little help!

      On Mon, 05 May 2008 11:47:59 +0200, Stevo <no@mail.invali dwrote:
      >Geoff Cox wrote:
      >I cannot see why this is not working - the idea being to check the
      >email address entered and if OK to move to either one of 2 pages - the
      >move does not happen.
      >
      >The simplest way to find out is to add alerts throught. That shows the
      >path the code is taking, and if you alert the values of things too,
      >it'll show you why. Example:
      >
      >function getNextPage(){
      >var num = Math.random();
      >alert("in getNextPage, random num="+num);
      > if (num<.5) {
      alert("in getNextPage, following<.5 logic")
      > location.href=" group1/group1-lab1.htm";
      > } else {
      alert("in getNextPage, following else logic")
      location.href=" group2/group2-lab1.htm";
      > }
      >}
      Thanks Stevo, I have tried your code but still not clear why my code
      isn't working!

      After

      alert("in getNextPage, following<.5 logic")

      I just see the original email address input and not

      group1/group1-lab1.htm

      Where next?!

      Cheers

      Geoff

      Comment

      • Geoff Cox

        #4
        Re: still hoping for a little help!

        On Mon, 05 May 2008 11:23:38 +0100, Geoff Cox <gcox@freeuk.no tcom>
        wrote:

        re

        function getNextPage(){
        var num = Math.random();
        alert("in getNextPage, random num="+num);
        if (num<.5) {
        alert("in getNextPage, following<.5 logic")
        location.href=" group1/group1-lab1.htm";
        } else {
        alert("in getNextPage, following else logic")
        location.href=" group2/group2-lab1.htm";
        }
        }

        I should have written that after seeing either

        alert("in getNextPage, following<.5 logic")

        or

        alert("in getNextPage, following else logic")

        I just get the original page back - no move to the new page?!

        Cheers

        Geoff

        Comment

        • Geoff Cox

          #5
          Re: still hoping for a little help!

          On Mon, 05 May 2008 11:47:59 +0200, Stevo <no@mail.invali dwrote:
          >Geoff Cox wrote:
          >I cannot see why this is not working - the idea being to check the
          >email address entered and if OK to move to either one of 2 pages - the
          >move does not happen.
          >
          >The simplest way to find out is to add alerts throught. That shows the
          >path the code is taking, and if you alert the values of things too,
          >it'll show you why. Example:
          >
          >function getNextPage(){
          >var num = Math.random();
          >alert("in getNextPage, random num="+num);
          > if (num<.5) {
          alert("in getNextPage, following<.5 logic")
          > location.href=" group1/group1-lab1.htm";
          > } else {
          alert("in getNextPage, following else logic")
          location.href=" group2/group2-lab1.htm";
          > }
          >}

          Stevo,

          I seems that the

          location.href=" group1/group1-lab1.htm";

          or the

          location.href=" group2group2lab 1.htm";

          is wrong - but they seem Ok to me ...?

          Cheers

          Geofg

          Comment

          • Matthias Watermann

            #6
            Re: still hoping for a little help!

            On Mon, 05 May 2008 09:04:46 +0100, Geoff Cox wrote:
            [...]
            I cannot see why this is not working - the idea being to check the
            email address entered and if OK to move to either one of 2 pages - the
            move does not happen.
            [...]
            function getNextPage(){
            var num = Math.random();
            if (num<.5) {
            location.href=" group1/group1-lab1.htm";
            } else {
            location.href=" group2/group2-lab1.htm";
            }
            }
            "location.h ref" is supposed to hold a _complete_ URL but your code
            misses at least the protocol and host parts (i.e. "http://www.dom.tld/").
            You might try using the "location.pathn ame" property which would accept
            your value. However, that would not cause the browser to change to
            that page.

            --
            Matthias
            /"\
            \ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
            X - AGAINST M$ ATTACHMENTS
            / \

            Comment

            • Geoff Cox

              #7
              Re: still hoping for a little help!

              On Mon, 05 May 2008 15:05:43 +0200, Matthias Watermann <lists@mwat.d e>
              wrote:
              >On Mon, 05 May 2008 09:04:46 +0100, Geoff Cox wrote:
              >
              >[...]
              >I cannot see why this is not working - the idea being to check the
              >email address entered and if OK to move to either one of 2 pages - the
              >move does not happen.
              >[...]
              >function getNextPage(){
              >var num = Math.random();
              > if (num<.5) {
              > location.href=" group1/group1-lab1.htm";
              > } else {
              > location.href=" group2/group2-lab1.htm";
              > }
              >}
              >
              >"location.href " is supposed to hold a _complete_ URL but your code
              >misses at least the protocol and host parts (i.e. "http://www.dom.tld/").
              >You might try using the "location.pathn ame" property which would accept
              >your value. However, that would not cause the browser to change to
              >that page.
              Matthias,

              I've tried the full URL (http:// etc) but no difference.

              Odd thing is that I have another file which uses a different type of
              check and that works OK - I cannot see the difference - this is it
              below. can you see the difference which accounts for it working?

              Cheers,

              Geoff

              function getNextPage(){
              var num = Math.random();
              if (num<.5) {
              location.href=" group1/group1-lab1.htm";
              } else {
              location.href=" group2/group2-lab1.htm";
              }
              }

              function CheckEmail(emai l) {

              AtPos = email.indexOf(" @");
              StopPos = email.lastIndex Of(".");

              if (email == "") {
              alert('Not a valid Email address');
              }

              if (AtPos == -1 || StopPos == -1) {
              alert('Not a valid email address');
              }

              if (StopPos < AtPos) {
              alert('Not a valid email address');
              }

              if (StopPos - AtPos == 1) {
              alert('Not a valid email address"');
              }

              document.emailF orm.email_addre ss.focus();
              document.emailF orm.email_addre ss.select();

              if (email != "" && (AtPos != -1 || StopPos != -1) && StopPos AtPos
              && StopPos - AtPos != 1) {
              parent.frame_to p.top_value = email;
              getNextPage();
              }

              }

              Comment

              • Matthias Watermann

                #8
                Re: still hoping for a little help!

                On Mon, 05 May 2008 14:45:37 +0100, Geoff Cox wrote:
                [...]
                >>I cannot see why this is not working - the idea being to check the
                >>email address entered and if OK to move to either one of 2 pages - the
                >>move does not happen.
                >>[...]
                >>function getNextPage(){
                >>var num = Math.random();
                >> if (num<.5) {
                >> location.href=" group1/group1-lab1.htm";
                >> } else {
                >> location.href=" group2/group2-lab1.htm";
                >> }
                >>}
                >>
                >>"location.hre f" is supposed to hold a _complete_ URL but your code
                >>misses at least the protocol and host parts (i.e. "http://www.dom.tld/").
                >>You might try using the "location.pathn ame" property which would accept
                >>your value. However, that would not cause the browser to change to
                >>that page.
                >
                Matthias,
                >
                I've tried the full URL (http:// etc) but no difference.
                How do you define "no difference"? Just by (visual appearance)? Or did
                you check the web-server logs to see whether there was a request
                actually? Quite possibly the browser could have requested something
                but failed (for whatever reasons) to update the display. But that's
                just a wild guess.
                Odd thing is that I have another file which uses a different type of
                check and that works OK - I cannot see the difference - this is it
                below. can you see the difference which accounts for it working?
                Well, no. I'd recommend to create a test page _without_ frames (which
                are an evil of the last century anyway) just to make sure, your
                JavaScript code works at all. Only _after_ you've verified that each
                snippet works as intended/expected include the code in your "real"
                pages.

                To check email addresses I'm using a simple RegEx:

                var _reMail = /^\s*([\w\x2D\x2E]+\@([\w\x2D]+\x2E)+[A-Za-z]{2,5})/;

                This is used by the onchange/onblur event method

                function cbMail() {
                if (! this.value) {
                return; // nothing to do
                } // if
                var h = _reMail.exec(th is.value);
                // required minimum: 12@4.67 or 1@34.67
                this.value = ((h) && (h[1]) && (6 < h[1].length)) ? h[1] : '';
                } // cbMail()

                which I assign to the respective form field objects. In the form
                object's submit handler then I've to check just whether there's a
                value of not.


                --
                Matthias
                /"\
                \ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
                X - AGAINST M$ ATTACHMENTS
                / \

                Comment

                • Janwillem Borleffs

                  #9
                  Re: still hoping for a little help!

                  Geoff Cox schreef:
                  Hello
                  >
                  I cannot see why this is not working - the idea being to check the
                  email address entered and if OK to move to either one of 2 pages - the
                  move does not happen.
                  >
                  The code below is in the lower of 2 frames.
                  >
                  Perhaps browser caching is your problem, try the following:

                  if (num<.5) {
                  location.href=" group1/group1-lab1.htm?" + num;
                  } else {
                  location.href=" group2/group2-lab1.htm?" + num;
                  }


                  JW

                  Comment

                  • Geoff Cox

                    #10
                    Re: still hoping for a little help!

                    On Mon, 05 May 2008 17:35:06 +0200, Janwillem Borleffs
                    <jw@jwscripts.c omwrote:
                    >Geoff Cox schreef:
                    >Hello
                    >>
                    >I cannot see why this is not working - the idea being to check the
                    >email address entered and if OK to move to either one of 2 pages - the
                    >move does not happen.
                    >>
                    >The code below is in the lower of 2 frames.
                    >>
                    >
                    >Perhaps browser caching is your problem, try the following:
                    >
                    >if (num<.5) {
                    location.href=" group1/group1-lab1.htm?" + num;
                    >} else {
                    location.href=" group2/group2-lab1.htm?" + num;
                    >}
                    >
                    >
                    >JW
                    tried the above - no change!

                    Cheers

                    Geoff

                    Comment

                    • VK

                      #11
                      Re: still hoping for a little help!

                      On May 5, 12:04 pm, Geoff Cox <g...@freeuk.no tcomwrote:
                      Hello
                      >
                      I cannot see why this is not working - the idea being to check the
                      email address entered and if OK to move to either one of 2 pages - the
                      move does not happen.
                      >
                      The code below is in the lower of 2 frames.
                      >
                      Why?!
                      >
                      Cheers
                      >
                      Geoff
                      >
                      function getNextPage(){
                      var num = Math.random();
                      if (num<.5) {
                      location.href=" group1/group1-lab1.htm";
                      } else {
                      location.href=" group2/group2-lab1.htm";
                      }
                      >
                      }
                      >
                      function validateEmail ( emailField, errorMsg ) {
                      emailpat =
                      /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
                      if( !emailpat.test( emailField.valu e ) ) {
                      alert( errorMsg);
                      emailField.focu s();
                      emailField.sele ct();
                      return false;
                      } else {
                      getNextPage();
                      }
                      >
                      }
                      >
                      //-->
                      </script>
                      >
                      </head>
                      >
                      <body>
                      >
                      <h2>test</h2>
                      >
                      <form name="emailForm " onsubmit="valid ateEmail( this.email , 'Please
                      enter a valid email address')">
                      Please enter your email address <input type="text" name="email">
                      <input type="submit" value="enter">
                      </form>
                      in case of a valid e-mail the flow goes to getNextPage

                      getNextPage sets location.href and exits without return value

                      onsubmit treats it as "OK to submit" and submits the form

                      action attribute if your form is not sets which defaults to
                      action="current URL" so the page gets reloaded

                      on page reload script gets reloaded as well so whatever location
                      change are made being lost

                      -------------------------------

                      make you getNextPage return false as well

                      Comment

                      • Geoff Cox

                        #12
                        Re: still hoping for a little help!

                        On Mon, 05 May 2008 17:29:52 +0200, Matthias Watermann <lists@mwat.d e>
                        wrote:
                        >On Mon, 05 May 2008 14:45:37 +0100, Geoff Cox wrote:
                        >
                        >[...]
                        >>>I cannot see why this is not working - the idea being to check the
                        >>>email address entered and if OK to move to either one of 2 pages - the
                        >>>move does not happen.
                        >>>[...]
                        >>>function getNextPage(){
                        >>>var num = Math.random();
                        >>> if (num<.5) {
                        >>> location.href=" group1/group1-lab1.htm";
                        >>> } else {
                        >>> location.href=" group2/group2-lab1.htm";
                        >>> }
                        >>>}
                        >>>
                        >>>"location.hr ef" is supposed to hold a _complete_ URL but your code
                        >>>misses at least the protocol and host parts (i.e. "http://www.dom.tld/").
                        >>>You might try using the "location.pathn ame" property which would accept
                        >>>your value. However, that would not cause the browser to change to
                        >>>that page.
                        >>
                        >Matthias,
                        >>
                        >I've tried the full URL (http:// etc) but no difference.
                        >
                        >How do you define "no difference"? Just by (visual appearance)? Or did
                        >you check the web-server logs to see whether there was a request
                        >actually? Quite possibly the browser could have requested something
                        >but failed (for whatever reasons) to update the display. But that's
                        >just a wild guess.
                        Here's a clue?!

                        If I use FF I do not get the move to either of the 2 pages but if I
                        step through the script with Firebug it works!

                        Why?

                        Cheers

                        Geoff
                        >
                        >Odd thing is that I have another file which uses a different type of
                        >check and that works OK - I cannot see the difference - this is it
                        >below. can you see the difference which accounts for it working?
                        >
                        >Well, no. I'd recommend to create a test page _without_ frames (which
                        >are an evil of the last century anyway) just to make sure, your
                        >JavaScript code works at all. Only _after_ you've verified that each
                        >snippet works as intended/expected include the code in your "real"
                        >pages.
                        >
                        >To check email addresses I'm using a simple RegEx:
                        >
                        >var _reMail = /^\s*([\w\x2D\x2E]+\@([\w\x2D]+\x2E)+[A-Za-z]{2,5})/;
                        >
                        >This is used by the onchange/onblur event method
                        >
                        >function cbMail() {
                        > if (! this.value) {
                        > return; // nothing to do
                        > } // if
                        > var h = _reMail.exec(th is.value);
                        > // required minimum: 12@4.67 or 1@34.67
                        > this.value = ((h) && (h[1]) && (6 < h[1].length)) ? h[1] : '';
                        >} // cbMail()
                        >
                        >which I assign to the respective form field objects. In the form
                        >object's submit handler then I've to check just whether there's a
                        >value of not.

                        Comment

                        • Geoff Cox

                          #13
                          Re: still hoping for a little help!

                          On Mon, 5 May 2008 14:33:29 -0700 (PDT), VK <schools_ring@y ahoo.com>
                          wrote:

                          >>
                          ><body>
                          >>
                          ><h2>test</h2>
                          >>
                          ><form name="emailForm " onsubmit="valid ateEmail( this.email , 'Please
                          >enter a valid email address')">
                          >Please enter your email address <input type="text" name="email">
                          ><input type="submit" value="enter">
                          ></form>
                          >
                          >in case of a valid e-mail the flow goes to getNextPage
                          >
                          >getNextPage sets location.href and exits without return value
                          >
                          >onsubmit treats it as "OK to submit" and submits the form
                          >
                          >action attribute if your form is not sets which defaults to
                          >action="curren t URL" so the page gets reloaded
                          >
                          >on page reload script gets reloaded as well so whatever location
                          >change are made being lost
                          >
                          >-------------------------------
                          >
                          >make you getNextPage return false as well
                          Brilliant!

                          <form name="emailForm " onsubmit="valid ateEmail( this.email , 'Please
                          enter a valid email address');retur n false;">

                          The return false gets the next page - thanks for your analysis!

                          Cheers

                          Geoff

                          Comment

                          • Geoff Cox

                            #14
                            Re: still hoping for a little help!

                            On Mon, 05 May 2008 17:29:52 +0200, Matthias Watermann <lists@mwat.d e>
                            wrote:


                            Matthias,

                            VK spotted the reason! - the missing return false in

                            <form name="emailForm " onsubmit="valid ateEmail( this.email , 'Please
                            enter a valid email address');retur n false;">

                            I'll have a look at your code below now. Thanks for that.

                            Cheers

                            Geoff

                            >To check email addresses I'm using a simple RegEx:
                            >
                            >var _reMail = /^\s*([\w\x2D\x2E]+\@([\w\x2D]+\x2E)+[A-Za-z]{2,5})/;
                            >
                            >This is used by the onchange/onblur event method
                            >
                            >function cbMail() {
                            > if (! this.value) {
                            > return; // nothing to do
                            > } // if
                            > var h = _reMail.exec(th is.value);
                            > // required minimum: 12@4.67 or 1@34.67
                            > this.value = ((h) && (h[1]) && (6 < h[1].length)) ? h[1] : '';
                            >} // cbMail()
                            >
                            >which I assign to the respective form field objects. In the form
                            >object's submit handler then I've to check just whether there's a
                            >value of not.

                            Comment

                            • nobody@nowhere.net

                              #15
                              Re: still hoping for a little help!

                              On Mon, 05 May 2008 09:04:46 +0100, Geoff Cox <gcox@freeuk.no tcom>
                              wrote:
                              >Hello
                              >
                              >I cannot see why this is not working - the idea being to check the
                              >email address entered and if OK to move to either one of 2 pages - the
                              >move does not happen.
                              >
                              >The code below is in the lower of 2 frames.
                              >
                              >Why?!
                              >
                              >Cheers
                              >
                              >Geoff
                              >
                              >
                              >function getNextPage(){
                              >var num = Math.random();
                              > if (num<.5) {
                              > location.href=" group1/group1-lab1.htm";
                              > } else {
                              location.href=" group2/group2-lab1.htm";
                              > }
                              >}
                              >
                              >function validateEmail ( emailField, errorMsg ) {
                              >emailpat =
                              >/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
                              > if( !emailpat.test( emailField.valu e ) ) {
                              > alert( errorMsg);
                              > emailField.focu s();
                              > emailField.sele ct();
                              > return false;
                              > } else {
                              > getNextPage();
                              > }
                              >}
                              >
                              >//-->
                              ></script>
                              >
                              ></head>
                              >
                              ><body>
                              >
                              ><h2>test</h2>
                              >
                              ><form name="emailForm " onsubmit="valid ateEmail( this.email , 'Please
                              >enter a valid email address')">
                              >Please enter your email address <input type="text" name="email">
                              ><input type="submit" value="enter">
                              ></form>
                              Try to replace type="submit" with type="button" and call validateEmail
                              in onclick event.

                              NNN

                              Comment

                              Working...