Question: Hello, I am having an issue getting the cookies working. All of my validations are working and I added the cookies code, but apparently not
Hello,
I am having an issue getting the cookies working. All of my validations are working and I added the cookies code, but apparently not quite right. My assignment is below with my code:
Assignment Instructions:
Collect and store form information in a cookie and display it on a Web page. Modify the "registration.html" page created in the prior assessment to send a query (that has all input field information from that form) to a second page (interests.html (created by you)). The information should be stored in hidden input fields (in the interests.html page) using the same field id/name. The interests page should ask the user to enter the following in optional fields:
Interests (list at least three using a checkbox).
Newsletter sign up (radio box with a yes/no option).
Comments (free form text area).
Referred by (text field).
When the user presses submit, all of the input fields from this form as well as the registration.html form will be saved into a cookie. The user should then be forwarded to a third page (confirm.html (created by you)) that will read the cookie information and display it in a name/value pair using JavaScript.
Make sure to do the following:
1. Create and integrate a script on the registration.html page that stores the input field data into hidden fields to be used in the interests.html page once the submit button is pressed.
2. Create an interests.html page with a form that has the fields listed above. This interests.html page will read in the input from the query string data from the registration.html page and store them into hidden input fields.
3. Write a script that runs in response to the submit event, from the interests.html page, that saves the input from both pages to a series of cookies to store each input, and opens a third page called confirm.html that reads and displays information from all the fields.
Registration HTML:
Yes No
Existing JS to add cookies to:
// 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;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
