Practice exercises CHAPTER 15 577
ns.save = function () {
var contact = currentRecord.contact;
contact.firstName = $('#firstName').val();
contact.lastName = $('#lastName').val();
contact.email = $('#email').val();
contact.phoneNumber = $('#phoneNumber').val();
var results = retrieveFromStorage();
if (currentRecord.key != null) {
results[currentRecord.key] = contact;
}
else {
results.push(contact);
}
localStorage.setItem('contacts', JSON.stringify(results));
ns.display();
};
})();
- In the Solution Explorer window, right-click the default.html file and choose Set As
Start Page. - Run the website and start adding contacts. Try closing the browser and rerunning the
website to see the persisted contacts.
Figure 15-1 shows the completed webpage with a fictitious contact added.
FIGURE 15-1 he completed contact bookT