html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!-- Contact Manager, based on the example in the edX course JavaScript Introduction
Adapted:
- improved CSS
- added column to delete contacts with .splice()
- search the table dynamically and case-insensitive with oninput, .search(), and .toLowerCase()
- sort by name (but not yet by email)
Still to do:
- sort by email
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Contact Manager v2, Local Storage</title>
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
<meta name="viewport" charset="UTF-8" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta charset="utf-8"/>
</head>
<body>
<h1>Contact Manager - Local Storage</h1>
<form onsubmit="return formSubmitted();">
<fieldset>
<legend>Personal info</legend>
<label>
Name
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
body {
margin: 0;
padding: 20px 15%;
background-color: yellowgreen;
font-family: Montserrat, sans-serif;
}
h1 {
text-align: center;
text-shadow: 2px 2px 2px lightgray;
}
table {
margin-top: 20px;
max-width: 100vw;
table-layout: auto;
width: 100%;
}
table, th, tr, td {
border: 1px solid;
border-collapse: collapse;
width: 100%;
padding: 8px 16px;
text-align: left;
}
th {
background-color: seagreen;
color: lightyellow;
font-size: 1.2rem;
font-weight: 100;
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
window.onload= init;
// The contact manager as a global variable
let cm;
function init() {
// create an instance of the contact manager
cm = new ContactManager();
cm.addTestData();
// cm.printContactsToConsole();
// Display contacts in a table
// Pass the id of the HTML element that will contain the table
cm.displayContactsAsATable("contacts");
}
function formSubmitted() {
// Get the values from input fields
let name = document.querySelector("#name");
let email = document.querySelector("#email");
let newContact = new Contact(name.value, email.value);
cm.add(newContact);
// Empty the input fields
name.value = "";
email.value = "";
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run