JS form redirecting once validated

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fernando b
    New Member
    • Nov 2010
    • 3

    JS form redirecting once validated

    Hi, I was wondering if you could please help. I am working on a dummy site and I have used javascript to validate my form, and it appears to be work. I now want the validated form to link to a new webpage. I do not need to retain any of the inputted form informtion, i just need it to redirect to a new webpage once the form has been validated.

    Many thanks in advance!...

    Code:
    var x;
    var myname;
    var surname;
    var email;
    var confirmmail;
    var dateofbirth;
    var at;
    var dot;
    var slash;
    
    		function validate1()
    	{
    		x=document.myForm;
    		at=x.myEmail.value.indexOf("@");
    		dot=x.myEmail.value.indexOf(".");
    		slash=x.dob.value.indexOf("/");
    		firstname=x.myname.value;
    		surname1=x.surname.value;
    		email=x.myEmail.value;
    		confirmmail=x.eConfirm.value;
    		dateofbirth=x.dob.value;
    		
    		
    		x.myname.className.replace('error','');
    		
    		if (firstname =="")
     			{
     			alert("Please Enter Your First Name");
    			x.myname.focus();
    			x.myname.className='error';			
    			return false;
    			}
    		else if(isNaN(firstname)== false)
    			{	
    			alert("Please Enter Your First Name Correctly");
    			x.myname.focus();
    			return false;
    			}
    		
    		else if (surname1 =="")
     			{
     			alert("You Enter Your Surname Name");
    			x.surname.focus();
    			return false;
    			}
    		else if(isNaN(surname1)== false)
    			{	
    			alert("Please Enter Surname Correctly");
    			x.surname.focus();
    			return false;
    			}
    			
    			
    		else if(email == "")
             	{	
    			alert("Please Enter A Vaild E-mail Address");
    			x.myEmail.focus();
    			return false;
    	 		}
    			else if (at==-1) 
    			{
    			alert("Please enter a vaild e-mail address2");
    			x.myEmail.focus();
    			return false;
    	 		}
    			else if (dot==-1) 
    			{
    			alert("Please enter a vaild e-mail address3");
    			x.myEmail.focus();
    			return false;
    			
    			
    	 		}
    		else if(confirmmail == "")
             	{	
    			alert("Please Confirm Your E-mail Address");
    			x.eConfirm.focus();
    			return false;
    	 		}
    			else if (at==-1) 
    			{
    			alert("Please Confirm Your Vaild E-mail Address ");
    			x.eConfirm.focus();
    			return false;
    	 		}
    		else if (dot==-1) 
    			{
    			alert("Please Enter A Vaild E-mail Address ");
    			x.eConfirm.focus();
    			return false;
    			
    			
    	 		}					
    		else if(dateofbirth=="")
    			{
    			alert("Please Enter Your Date of Birth");
    			x.dob.focus();
    			return false;
    			}
    			else if(slash==-1) 			
    			{
    			alert("Please Enter Your Date of Birth in the Following Format: DD/MM/YYYY");
    			x.dob.focus();
    			return false;
    			}
    			
    		
    		return true;
    		} 
    </script>
     
     <form name="myForm" action="submitform.html" onSubmit="return validate1();">
    			
    			Enter Your First Name: 
    			<input type="text" name="myname"/> 
    			<br/>
    
    			Enter Your Surname: 
    			<input type="text" name="surname"/> 
    			<br/>
    			
    			Enter Your Email Address: 
    			<input type="text" name="myEmail"/> 
    			<br/>
    			
    			Confirm Your Email Address: 
    			<input type="text" name="eConfirm"/> 
    			<br/>
    			
    			Enter Your Date of Birth: 
    			<input type="text" name="dob"/> 
    			<br/>
    			
    			
    			<input type="Submit" value="Confirm"  target="blank"/> 
    			<input type="Submit" value="Reset"/>
    			<br/>
    			
    			</form>
    Last edited by Dormilich; Nov 27 '10, 02:53 PM. Reason: please use [CODE] [/CODE] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    doesn’t your code already do that?

    Comment

    • fernando b
      New Member
      • Nov 2010
      • 3

      #3
      Thanks for the reply..
      Once the form goes through the validation process it does not redirect to any particular page, it just seems to crash. How can I direct to a different webpage, this is my problem?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        if it seems to crash, there should be written something in the Error Console.

        Comment

        • fernando b
          New Member
          • Nov 2010
          • 3

          #5
          Problem solved! i didn't realsie the action tag (below)was the corret location for the link. You learn something new everyday! Thanks for your help
          <form name="myForm" action="submitf orm.html" onSubmit="retur n validate1();">

          Comment

          Working...