Question: in the following javascript code follow the direction Hands-on Project 8-1 Hands-on Project 8-1 New Account Information First Name Last Name Street Address City State

in the following javascript code follow the direction

Hands-on Project 8-1

Hands-on Project 8-1

New Account Information

1.Before the closing tag, add the following script element, save your changes, and then close index.htm:

 

2. Add a statement instructing processors to interpret the document contents in strict mode. Add another statement declaring a global variable named newAccountArray with an empty array as its value.

. 3. Declare a new function named createID(). Declare the local variables listed in Table - , with values referencing the elements with the id values shown.

VARIABLE

ELEMENT ID VALUE

fname

fnameinput

lname

lnameinput

zip

zipinput

account

accountidbox 

Table 8-8: Variable names and corresponding element ids

4.Also declare a local variable named fields with a value that references all elements with the tag name input. Finally, declare the local variables acctid, firstInit, and lastInit with no values.

. 5. WithinthecreateID()function,createanifstatementthatchecksifthevalues of the elements referenced by the fname, lname, and zip variables are all non-null. (Hint: Check if each value is not equal to an empty string ("").) Add the following statements to run if the condition is true:

firstInit = fname.value.charAt(0).toUpperCase();

lastInit = lname.value.charAt(0).toUpperCase();

acctid = firstInit + lastInit + zip.value;

account.value = acctid;

newAccountArray = [];

for (var i = 0; i < fields.length - 1; i++) {

newAccountArray.push(fields[i].value);

}

. This code uses the charAt() method of the String object to assign the first letter of the users first and last names to the firstInit and lastInit variables. Next it creates the acctid value by concatenating the first initial, last initial, and zip code, then assigns that value to the Account ID field in the form. Finally, it ensures that the newAccountArray variable is empty, and then uses a for loop to add the value of each form field to the array with the push() method.

6.

Add the following function to create event listeners:

.

.

Save your changes to script.js, then open index.htm in your browser. Enter your name and address (or a fictitious name and address) in the form. After entering a Zip value, press Tab. The Account ID value is created automatically.

Open your browser console, type newAccountArray, press Enter, and then, if necessary, click object Array to view the array contents. As Figure - shows, the array contents, including the Account ID, are all elements in the newAccountArray variable.

6.Add the following function to create event listeners:

function createEventListeners() { var fname = document.getElementById("fnameinput"); var lname = document.getElementById("lnameinput"); var zip = document.getElementById("zipinput"); if (fname.addEventListener) { 
 fname.addEventListener("change", createID, false); lname.addEventListener("change", createID, false); zip.addEventListener("change", createID, false); 
 } else if (fname.attachEvent) { fname.attachEvent("onchange", createID); lname.attachEvent("onchange", createID); zip.attachEvent("onchange", createID); 

}

}

if

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To provide a detailed answer well break down each part of the process d... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!