Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

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();
};

})();


  1. In the Solution Explorer window, right-click the default.html file and choose Set As
    Start Page.

  2. 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
Free download pdf