I myself study JS and work on an exercise that takes input from the user (first name, middle name, last name) and stores the input data in the JS object (later I will manipulate the object itself and sort it, check for duplicates, etc.)
I searched everywhere and can’t find any direction on this. I am familiar with saving HTML input as variables (var n = document.getElementById ('x'). Value), but I'm very new to objects.
How do I save user login to objects? And can I save the “multiples” views in an object, like in “load an object from user input” and then process it at a later stage?
HTML:
<body> <label>First Name: <input type='text' name='firstName' id='firstName' placeholder="First Name"> </label> <br> <br> <label>Middle Name: <input type='text' name='middleName' id='middleName' placeholder="Middle Name"> </label> <br> <br> <label>Last Name: <input type='text' name='lastName' id='lastName' placeholder="Last Name"> </label> <br> <br> <button type="button" onclick="buildList()">Add to List</button> </body>
I think that the JS object should look like this, and every time the user clicks "Add to list", the program adds another name to the list "First / Middle / Last" .:
var list = { firstName:"John", middleName:"Will", lastName:"Doe" }, { firstName:"Ben", middleName:"Thomas", lastName:"Smith" }, { firstName:"Brooke", middleName:"James", lastName:"Kanter" };
*** Please note that later I plan to read the frequency of each first / middle / last name and display it on the screen .. ie: 'FirstName'Jason: 2, 'FirstName'Ed:3; 'MiddleName'Marie:5; 'LastName'Smith:3' 'FirstName'Jason: 2, 'FirstName'Ed:3; 'MiddleName'Marie:5; 'LastName'Smith:3'
My goal: create a list of full names. Break them into three lists: first, middle and last names. Count the frequency of the names in each list. --- I figured that using an object would be the best way to do this.