function Contact() { this.lastName; this.firstName; this.telephone; this.address; this.city; this.state; this.zip; this.getContacts = getContactInfo; this.updateContact = updateSelectedContact; } var contactCounter = 0; var contactList = new Array(); var newContact = contactCounter; contactList[newContact] = new Contact(); function addContact() { if (document.forms[3].lastname.value == "" || document.forms[3].firstname.value == "") window.alert("You must enter the contact's first and last names."); else { if (document.forms[3].contacts.options[0].value == "contacts" || document.forms[3].contacts.options[0].value == null) document.forms[3].contacts.options[0] = null; var newContact = contactCounter; contactList[newContact] = new Contact(); contactList[newContact].lastName = document.forms[3].lastname.value; contactList[newContact].firstName = document.forms[3].firstname.value; contactList[newContact].telephone = document.forms[3].telephone.value; contactList[newContact].address = document.forms[3].address.value; contactList[newContact].city = document.forms[3].city.value; contactList[newContact].state = document.forms[3].state.value; contactList[newContact].zip = document.forms[3].zip.value; var createContact = new Option(); createContact.value = contactList[newContact].lastName + ", " + contactList[newContact].firstName; createContact.text = contactList[newContact].lastName + ", " + contactList[newContact].firstName; var numContacts = document.forms[3].contacts.options.length; document.forms[3].contacts.options[numContacts] = createContact; document.forms[3].lastname.value = ""; document.forms[3].firstname.value = ""; document.forms[3].telephone.value = ""; document.forms[3].address.value = ""; document.forms[3].city.value = ""; document.forms[3].state.value = ""; document.forms[3].zip.value = ""; ++contactCounter; } document.forms[3].userInfo.value = "--> Continue adding more contacts in the same way"; document.forms[3].userInfo2.value = "--> To remove a contact, select from the list and press 'Delete Contact'"; document.forms[3].userInfo3.value = "--> To retrieve information, select contact from the list"; document.forms[3].userInfo4.value = " >To update contact information, modify specific fields then press 'Update Contact'"; } function getContactInfo() { if (document.forms[3].contacts.options[0].value == "contacts") window.alert("You must enter the contact's information first."); else { document.forms[3].lastname.value = this.lastName; document.forms[3].firstname.value = this.firstName; document.forms[3].telephone.value = this.telephone; document.forms[3].address.value = this.address; document.forms[3].city.value = this.city; document.forms[3].state.value = this.state; document.forms[3].zip.value = this.zip; } } function updateSelectedContact(curIndex) { this.lastName = document.forms[3].lastname.value; this.firstName = document.forms[3].firstname.value; this.telephone = document.forms[3].telephone.value; this.address = document.forms[3].address.value; this.city = document.forms[3].city.value; this.state = document.forms[3].state.value; this.zip = document.forms[3].zip.value; document.forms[3].contacts.options[curIndex].value = this.lastName + ", " + this.firstName; document.forms[3].contacts.options[curIndex].text = this.lastName + ", " + this.firstName; window.alert("Contact information updated."); } function deleteContact() { var selectedContact = 0; var contactSelected = false; while (selectedContact < document.forms[3].contacts.length) { if (document.forms[3].contacts.options[selectedContact].selected == true) { contactSelected = true; break; } ++selectedContact; } if (contactSelected == true) { document.forms[3].contacts.options[selectedContact] = null; contactList.splice(selectedContact, 1); } else window.alert("You must select a contact in the list."); document.forms[3].lastname.value = ""; document.forms[3].firstname.value = ""; document.forms[3].telephone.value = ""; document.forms[3].address.value = ""; document.forms[3].city.value = ""; document.forms[3].state.value = ""; document.forms[3].zip.value = ""; } function newInput() { document.forms[3].lastname.focus(); document.forms[3].lastname.value = ""; document.forms[3].firstname.value = ""; document.forms[3].telephone.value = ""; document.forms[3].address.value = ""; document.forms[3].city.value = ""; document.forms[3].state.value = ""; document.forms[3].zip.value = ""; document.forms[3].userInfo.value = "--> After entering information press 'Add Contact'"; }