Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How to move from one page to another

<html>
    <head>
        <title>Basic Form Validation</title>
        <style>
            #regform{
            margin:0 auto;
            width:600px;
            padding:14px;
            }

            input{
                font-size:12px;
            padding:4px 2px;
            border:solid 1px #aacfe4;
            width:200px;
            margin:2px 5px 10px 10px;
            }
            #label {
            float: left;
            width: 100px;
            padding: 0 1em;
            text-align: right;
            }
            div{
            margin-bottom: .5em;
            padding: 0;
            display: block;
            }

        </style>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.js"></script>
        <script>

            $(function(){
                $("#regform").validate()({;     
 submitHandler: function(form){
      location.replace('http://www.google.com');
      form.submit();
      }
});
});
            </script>

    </head>
    <body>
        <form id="regform" method="post" action="p.php">
            <div class="wrap">  
                <label id="label" for="username">Username</label>
                <input type="text" name="us" id="username" class="required" minlength="6"/>
            </div>

            <div class="wrap">  
                <label id="label" for="pass">Password</label>
                <input type="password" name="ps" id="pass" class="required" minlength="6"/>
            </div>

            <div class="wrap">  
                <label id="label" for="rpass">Retype Password</label>
                <input type="password" name="rpass" id="rpass" class="required" equalTo="#pass"/>
            </div>

            <div class="wrap">  
                <label id="label" for="useremail">Email</label>
                <input type="text" name="useremail" id="useremail" class="required email"/>
            </div>

            <div class="wrap">  
                <label id="label" for="mobile">Mobile</label>
                <input type="text" name="mobile" id="mobile" class="required digits" minlength="10" maxlength="10"/>
            </div>

            <div class="wrap">  
                <label id="label" for="mobile">&nbsp;</label>
                <input type="submit" id="submit"/>
            </div>

        </form>
        <a href="login1.php">Already Registered</a>
    </body>
</html>

2 Answers

I'm not 100% sure I know what your trying to achieve but I think you're over complicating things. The form will be submitted to the file specified in

<form id="regform" method="post" action="p.php">

In this case p.php. This can be the same page as the form or a different one and will need the server side code to process the form data. I can't think why you would want to use Javascript to redirect to a different page before the form is submitted (you will loose all the form data). Have I missed what you're trying to achieve?

No worries!! I got it!!