Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. function Contact(fname, lname, address, email, phone) {
  2. this.fname = fname;
  3. this.lname = lname;
  4. this.address = address;
  5. this.email = email;
  6. this.phone = phone;
  7. }
  8.  
  9. //The contacts
  10. var contacts = [];
  11.  
  12. var ul1 = document.createElement('ul');
  13. ul1.id = ('nav');
  14.  
  15. function theContacts() {
  16. var body = document.getElementsByTagName('body')[0],
  17. length = contacts.length;
  18. for (var i = 0; i < length; i++) {
  19. var cont = contacts[i],
  20. li = document.createElement('li'),
  21. ul = document.createElement('ul');
  22. li.innerHTML = cont.fname + ' ' + cont.lname;
  23. for (var key in cont) {
  24. var info = document.createElement('li');
  25. info.className = key;
  26. info.innerHTML = cont[key];
  27. ul.appendChild(info);
  28. }
  29. li.appendChild(ul); ul1.appendChild(li);
  30. }
  31. body.appendChild(ul1);
  32. }
  33.  
  34. function addForms(){
  35. var body = document.getElementsByTagName('body')[0]
  36. var form = document.createElement("form");
  37. form.id = 'formList';
  38. var myArray = ['fnameValue', 'lnameValue', 'addressValue', 'emailValue', 'phoneValue'];
  39. var texts = ['First Name: ', 'Last Name: ', 'Address: ', 'Email: ', 'Phone: '];
  40.  
  41. for(var i = 0; i < 5; i++){
  42. var input = document.createElement('input');
  43. var newlabel = document.createElement('label');
  44. newlabel.innerHTML = texts[i];
  45. form.appendChild(newlabel);
  46. input.setAttribute('type','text');
  47. input.setAttribute('id', myArray[i]);
  48.  
  49. // adds the input's to the form.
  50. form.appendChild(input);
  51. }
  52.  
  53. // adds the forms to the body
  54. body.appendChild(form);
  55.  
  56. // Add Contact Button
  57. var addContact = document.createElement('input')
  58. addContact.setAttribute('type', 'button')
  59. addContact.setAttribute('id', 'addContact')
  60. addContact.addEventListener('click', onClick);
  61. addContact.setAttribute('value', 'Add Contact')
  62. form.appendChild(addContact);
  63. }
  64.  
  65. function addNewContact() {
  66. var input1 = document.getElementById('fnameValue').value;
  67. var input2 = document.getElementById('lnameValue').value;
  68. var input3 = document.getElementById('addressValue').value;
  69. var input4 = document.getElementById('emailValue').value;
  70. var input5 = document.getElementById('phoneValue').value;
  71. contacts.length = 0;
  72. contacts.push(new Contact(input1, input2, input3, input4, input5));
  73. }
  74.  
  75. // Knappning fΓΆr ny kontakt
  76. var button = document.getElementById("newButton");
  77. button.addEventListener("click", addForms);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement