Advertisement
Guest User

Adressbok, exempel

a guest
Sep 27th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is our "global" address book array.
  2. // All code/functions/etc can access this variable, from everywhere.
  3. var allContacts = [];
  4.  
  5.  
  6.  
  7. // Get a reference to our "save" button and bind a "click" event listener to it.
  8. // The "listener" is in fact a function, that will be called when the button is clicked.
  9. var saveButton = document.getElementById("spara-knapp");
  10. saveButton.addEventListener("click", function () {
  11.  
  12.     // Get all the input values that the user has typed in our input fields, and save them in temporary variables for now.
  13.     var tempFirstName = document.getElementById("first-name-input").value;
  14.     var tempLastName = document.getElementById("last-name-input").value;
  15.     // ...do this for all input fields...
  16.  
  17.  
  18.     // Create a new object, that will be our new "contact".
  19.     // Store all of the input values in the object.
  20.     var contact = {
  21.         firstName: tempFirstName,
  22.         lastName: tempLastName
  23.     };
  24.  
  25.  
  26.     // Finally, we add the new contact object to our global variable, the address book array.
  27.     allContacts.push(contact);
  28.  
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement