473,378 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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!...

Expand|Select|Wrap|Line Numbers
  1. var x;
  2. var myname;
  3. var surname;
  4. var email;
  5. var confirmmail;
  6. var dateofbirth;
  7. var at;
  8. var dot;
  9. var slash;
  10.  
  11.         function validate1()
  12.     {
  13.         x=document.myForm;
  14.         at=x.myEmail.value.indexOf("@");
  15.         dot=x.myEmail.value.indexOf(".");
  16.         slash=x.dob.value.indexOf("/");
  17.         firstname=x.myname.value;
  18.         surname1=x.surname.value;
  19.         email=x.myEmail.value;
  20.         confirmmail=x.eConfirm.value;
  21.         dateofbirth=x.dob.value;
  22.  
  23.  
  24.         x.myname.className.replace('error','');
  25.  
  26.         if (firstname =="")
  27.              {
  28.              alert("Please Enter Your First Name");
  29.             x.myname.focus();
  30.             x.myname.className='error';            
  31.             return false;
  32.             }
  33.         else if(isNaN(firstname)== false)
  34.             {    
  35.             alert("Please Enter Your First Name Correctly");
  36.             x.myname.focus();
  37.             return false;
  38.             }
  39.  
  40.         else if (surname1 =="")
  41.              {
  42.              alert("You Enter Your Surname Name");
  43.             x.surname.focus();
  44.             return false;
  45.             }
  46.         else if(isNaN(surname1)== false)
  47.             {    
  48.             alert("Please Enter Surname Correctly");
  49.             x.surname.focus();
  50.             return false;
  51.             }
  52.  
  53.  
  54.         else if(email == "")
  55.              {    
  56.             alert("Please Enter A Vaild E-mail Address");
  57.             x.myEmail.focus();
  58.             return false;
  59.              }
  60.             else if (at==-1) 
  61.             {
  62.             alert("Please enter a vaild e-mail address2");
  63.             x.myEmail.focus();
  64.             return false;
  65.              }
  66.             else if (dot==-1) 
  67.             {
  68.             alert("Please enter a vaild e-mail address3");
  69.             x.myEmail.focus();
  70.             return false;
  71.  
  72.  
  73.              }
  74.         else if(confirmmail == "")
  75.              {    
  76.             alert("Please Confirm Your E-mail Address");
  77.             x.eConfirm.focus();
  78.             return false;
  79.              }
  80.             else if (at==-1) 
  81.             {
  82.             alert("Please Confirm Your Vaild E-mail Address ");
  83.             x.eConfirm.focus();
  84.             return false;
  85.              }
  86.         else if (dot==-1) 
  87.             {
  88.             alert("Please Enter A Vaild E-mail Address ");
  89.             x.eConfirm.focus();
  90.             return false;
  91.  
  92.  
  93.              }                    
  94.         else if(dateofbirth=="")
  95.             {
  96.             alert("Please Enter Your Date of Birth");
  97.             x.dob.focus();
  98.             return false;
  99.             }
  100.             else if(slash==-1)             
  101.             {
  102.             alert("Please Enter Your Date of Birth in the Following Format: DD/MM/YYYY");
  103.             x.dob.focus();
  104.             return false;
  105.             }
  106.  
  107.  
  108.         return true;
  109.         } 
  110. </script>
  111.  
  112.  <form name="myForm" action="submitform.html" onSubmit="return validate1();">
  113.  
  114.             Enter Your First Name: 
  115.             <input type="text" name="myname"/> 
  116.             <br/>
  117.  
  118.             Enter Your Surname: 
  119.             <input type="text" name="surname"/> 
  120.             <br/>
  121.  
  122.             Enter Your Email Address: 
  123.             <input type="text" name="myEmail"/> 
  124.             <br/>
  125.  
  126.             Confirm Your Email Address: 
  127.             <input type="text" name="eConfirm"/> 
  128.             <br/>
  129.  
  130.             Enter Your Date of Birth: 
  131.             <input type="text" name="dob"/> 
  132.             <br/>
  133.  
  134.  
  135.             <input type="Submit" value="Confirm"  target="blank"/> 
  136.             <input type="Submit" value="Reset"/>
  137.             <br/>
  138.  
  139.             </form>
Nov 27 '10 #1
4 1406
Dormilich
8,658 Expert Mod 8TB
doesn’t your code already do that?
Nov 27 '10 #2
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?
Nov 27 '10 #3
Dormilich
8,658 Expert Mod 8TB
if it seems to crash, there should be written something in the Error Console.
Nov 27 '10 #4
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="submitform.html" onSubmit="return validate1();">
Nov 27 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Randell D. | last post by:
Whats wrong with my sample script below? All I want to do is confirm that my form data is in my environment (basically, I'm writing a script that will check that some form fields have a value, and...
1
by: Konstantin | last post by:
Can someone help me figure out a way to open a form only once in an MDI app. I have an MDI app that contains several forms. I use each form depending on the type of document that the user needs...
4
by: Peloux | last post by:
Hi, I have written some htc in order to validate data in a form. most of htc are attached on 'onblur' event. Now, we would like to use the Enter Key to sublit form, so we use the following...
4
by: DraguVaso | last post by:
Hi, I want a Login-form that, once the username and password are validated, opens a new Form (of the 'main'-application), and closes itself. I tryed it like this: putting the following code in...
8
by: Brian Henry | last post by:
how would you disable all text boxes on a form at once/ I thought dim tx as textbox for each tx in me.controls tx.enabled = false next but that crashes, what do you guys suggest? thanks
24
by: Kelly | last post by:
Hey all - I need a little more help. I don't quite know why my text file or form isn't closing. Short version - this program takes data entered into a textbox, user clicks Save button, Save...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
5
by: jinukosh | last post by:
We are having multiple submit buttons with form validation on a single form. By default a button is selected and the elememts included in the form is validated. If we try to add 2 forms to an...
3
by: CrostonScottish | last post by:
I have a form listing all students in an Access 2003 database. One control button next to each students name has a macro which opens a new form designed specifically for the initial assessment. ...
1
by: IframeLearner | last post by:
Hi , I am trying to upload a file from a parent.jsp using Iframes. From Parent page. I have to save Subject, Desc, File and file name. to upload the file i am using Iframe. I want the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.