Question
Hello, I am trying to get the code below to go to another HTML page onsubmit (confirm.html) if all of the field validations are complete.
Hello,
I am trying to get the code below to go to another HTML page onsubmit (confirm.html) if all of the field validations are complete. I seem to have the code working for the checkValidity() function where the user cannot click the "Submit" button unless every field is complete and the individual fields validations are working as well. I can't figure out how to get it to go to the confirmation page (confirm.html) if everything checks. When i click the submit button right now, it clear the fields and puts the autofocus back on the first field, but never goes to the confirmation page. Please help me figure this last piece out.
HTML:
Yes No
JavaScript:
// function alphanumeric(str) {
// event.preventDefault();
//function to validate the User Name field has only letters and numbers only and is not blank
function userNameCheck() { var uname = document.form.userName; var letters = /^[0-9a-zA-Z]+$/;
if (uname.value === "") { alert("Error: User Name cannot be Blank. Please enter a valid User Name!"); uname.focus(); return false; }
if (uname.value.match(letters)) { document.form.password.focus(); return true; } else { alert("Please enter letters or number only with no special characters or spaces!"); uname.focus(); return false;
} }
//function to validate password has a minimum of 8 characters and is not blank function passidCheck(mn, my) { var passid = document.form.password; var passid_len = passid.value.length;
if (passid.value === "") { alert("Error: Password cannot be Blank. Please enter a valid Password!"); passid.focus(); return false; }
if (passid_len < 8) { alert("Please enter a minimum of 8 characters!"); passid.focus(); return false; } //Focus goes to next field document.form.passwordVerify.focus(); return true;
}
//function to confirm password matches first password and is not blank function confirmPassidCheck() {
var confirmpwEl = document.getElementById("passwordVerifyId");
var passid1 = document.getElementById("passwordId").value; var confirmpw = document.getElementById("passwordVerifyId").value;
// if (passid1 && confirmpw) { if (passid1 !== confirmpw) { // if (passid1.value != confirmpw.value) alert("Error: Confirm Password was either blank or did not match. Please re-enter the same password entered above!"); confirmpwEl.focus(); } }
//function to confirm first name entry and is not blank
function fnameCheck() { var fstName = document.form.firstName; var name1 = /^[a-zA-Z ]+$/;
if (fstName.value === "") { alert("Error: First Name cannot be Blank. Please enter a First Name!"); fstName.focus(); return false; }
if (fstName.value.match(name1)) { document.form.lastName.focus(); return true; } else { alert("Please enter a valid First Name using letters only!"); fstName.focus(); return false;
} }
//function to confirm last name entry and is not blank
function lnameCheck() { var lstName = document.form.lastName; var name1 = /^[a-zA-Z ]+$/;
if (lstName.value === "") { alert("Error: Last Name cannot be Blank. Please enter a Last Name!"); lstName.focus(); return false; }
if (lstName.value.match(name1)) { document.form.email.focus(); return true; } else { alert("Please enter a valid Last Name using letters only!"); lstName.focus(); return false;
} }
//function to validate the user entered a valid email address and is not blank function emailCheck() { var string1 = document.form.email.value; if (form.email.value === "") { alert("Error: Email Address cannot be Blank. Please enter a valid Email Address!"); document.form.email.focus(); return false; }
if (string1.indexOf("@") == -1) { //this means if @ is not in the string, do this alert("Please enter a valid Email Address!"); document.form.email.focus(); //this forces the cursor to be at the email text box field return false; } }
//Function to validate the phone number field entry and is not blank function phoneNumberCheck() { var uphone = document.form.phoneNumber; var phoneInput = /^[\+]?[(]?[0-9]{3}[)]?[\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;
if (uphone.value === "") { alert("Error: Phone Number cannot be Blank. Please enter a valid Phone Number!"); uphone.focus(); return false; }
if (uphone.value.match(phoneInput)) { return true;
} else { alert("Please enter 10 digit phone number!"); uphone.focus(); return false;
}
}
//Final check prior to submit and redirecting to the confirm page.
function checkValidity() { //variable to store all of the inputs for the validations on the form var inp = documents.getElementsByTagName("input"); var btn = document.getElementsById("btn");
for (var i = 0; i < inp.length; i++) { .disabled = "true"; } else { window.location: href.confirm.html; .innerHTML = "Button is Disabled"; } }
Confirm HTML:
Thank you for registering with Us
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started