Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is our "global" address book array.
- // All code/functions/etc can access this variable, from everywhere.
- var allContacts = [];
- // Get a reference to our "save" button and bind a "click" event listener to it.
- // The "listener" is in fact a function, that will be called when the button is clicked.
- var saveButton = document.getElementById("spara-knapp");
- saveButton.addEventListener("click", function () {
- // Get all the input values that the user has typed in our input fields, and save them in temporary variables for now.
- var tempFirstName = document.getElementById("first-name-input").value;
- var tempLastName = document.getElementById("last-name-input").value;
- // ...do this for all input fields...
- // Create a new object, that will be our new "contact".
- // Store all of the input values in the object.
- var contact = {
- firstName: tempFirstName,
- lastName: tempLastName
- };
- // Finally, we add the new contact object to our global variable, the address book array.
- allContacts.push(contact);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement