1. In the file script2.js, first change the line in the handleSubmit function which calls createCookies to instead call a function called saveSignUp.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

1. In the file script2.js, first change the line in the handleSubmit function which calls createCookies to instead call a
function called saveSignUp.
3. At the top of the file, create a new global object variable “signUp” to store the sign-up information.
4. Add the following properties to the object: name, email, phone, address, city, state, zip, foodAllergies,
frequency, size and initialize all to a blank string 
6. Define a new local array variable called “fields” in the populateInfo function.;
9. Immediately after the for loop, assign the properties of the signUp object to the values of the fields array you
just captured from the URL string.
10. Create a new function called saveSignUp().
11. Write a line of code to save the value of the textarea in the signUp object field for allergies.

scripts2.js

 

"use strict";
var queryArray = [];

function populateInfo() {
    if (location.search) {
        var queryData = location.search;
        var hiddenInputs = document.querySelectorAll("input[type=hidden]");
        queryData = queryData.substring(1, queryData.length);
        queryArray = queryData.split("&");
        for (var i = 0; i < queryArray.length; i++) {
            hiddenInputs[i].value = queryArray[i].substring(queryArray[i].lastIndexOf("=") + 1);
        }
    }
}

function createCookies() {
    var formFields = document.querySelectorAll("input[type=hidden],input[type=radio], textarea");
    var expireDate = new Date();
    expiresDate.setDate(expiresDate.getDate() + 7);
    for (var i = 0; i < formFields.length; i++) {
         var currentValue = decodeURIComponent(formFields[i].value);
         currentValue = currentValue.replace(/\+/g, " ");
    document.cookie = formFields[i].name + "=" + currentValue + "; expires=" + expiresDate.toUTCString();
    }
}

function handleSubmit(evt) {
    if (evt.preventDefault) {
        evt.preventDefault();
    } else {
    evt.returnValue = false;
    }
    createCookies();
    document.getElementsByTagName("form")[0].submit();
    
}

function createEventListeners() {
    var form = document.getElementsByTagName("form")[0];
    if (form.addEventListener) {
        form.addEventListener("submit", handleSubmit, false);
    } else if (form.attachEvent) {
        form.attachEvent("onsubmit", handleSubmit);
    }
}

function setupPage() {
    createEventListeners();
    populateInfo();
}


if (window.addEventListener) {
    window.addEventListener("load", setupPage, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", setupPage);
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY