why not move to new page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geoffcox
    New Member
    • Dec 2007
    • 1

    why not move to new page?

    hello

    the code below checks for a valid email address and then should move to either of 2 pages but no move happens! Why?

    Thanks

    Geoff

    [HTML]<script>
    function getNextPage(){
    var num = Math.random();
    if (num<.5) {
    alert('going to 1');
    location.href=' group1/group1-lab1.htm';
    } else {
    alert('going to 2');
    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 {
    //return true;
    parent.frame_to p.top_value = emailField.valu e;
    document.getEle mentById('mail' ).className='hi ddenDiv';
    getNextPage();
    }
    }

    //-->
    </script>
    </script>
    </head>
    <body>

    <h2>test</h2>

    <div id="mail" class="visibleD iv">
    <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>
    </div>[/HTML]
    Last edited by acoder; May 5 '08, 10:04 AM. Reason: Added code tags
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Remove the duplicate script end tag.

    Also, if you have to redirect the page to another page, what's the need of the email validation? I guess you want to change the action of the form instead of redirecting the browser.

    For that, in the end of second function, instead of writing getNextPage(), write return getNextPage() there.

    And modify your getNextPage() function like this...[code=javascript]function getNextPage(){
    var num = Math.random();
    if (num<0.5) {
    alert('going to 1');
    document.forms['emailForm'].action='group1/group1-lab1.htm';
    }
    else {
    alert('going to 2');
    document.forms['emailForm'].action='group2/group2-lab1.htm';
    }
    return true; //important
    }[/code]

    And don't forget this when you post here next time:
    [code] --- your code --- [/code] (Use code tags)

    Comment

    Working...