This repository was archived by the owner on Jul 6, 2024. It is now read-only.
forked from mhaidarhanif/address-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6069c9a
commit e9c827e
Showing
2 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,70 @@ | ||
const contactContainerElement = document.getElementById("contact-container"); | ||
|
||
function renderContactById() { | ||
const contacts = loadContacts(); | ||
|
||
function getCurrentContactId() { | ||
const queryString = window.location.search; | ||
const params = new URLSearchParams(queryString); | ||
const id = Number(params.get("id")); | ||
|
||
const contact = contacts.find((contact) => contact.id === id); | ||
return id; | ||
} | ||
|
||
function renderContactById() { | ||
const id = getCurrentContactId(); | ||
const contact = loadContactById(id); | ||
|
||
contactContainerElement.innerHTML = ` | ||
<h2>${contact.fullName}</h2> | ||
<p>${contact.email}</p> | ||
<p>${contact.phone}</p> | ||
<div> | ||
<button onclick="renderContactEditFormById(${contact.id})">Edit</button> | ||
<button onclick="deleteContactById(${contact.id})">Delete</button> | ||
</div> | ||
`; | ||
} | ||
|
||
function renderContactEditFormById(id) { | ||
const contact = loadContactById(id); | ||
|
||
contactContainerElement.innerHTML = ` | ||
<form id="edit-contact-form" method="post"> | ||
<div> | ||
<label for="full-name">Full name:</label> | ||
<input | ||
id="full-name" | ||
name="fullName" | ||
type="text" | ||
placeholder="Elon Musk" | ||
value="${contact.fullName}" | ||
/> | ||
</div> | ||
<div> | ||
<label for="email">Email address:</label> | ||
<input | ||
id="email" | ||
name="email" | ||
type="email" | ||
placeholder="[email protected]" | ||
value="${contact.email}" | ||
/> | ||
</div> | ||
<div> | ||
<label for="phone">Phone number:</label> | ||
<input id="phone" name="phone" type="phone" placeholder="+1234567890" | ||
value="${contact.phone}" | ||
/> | ||
</div> | ||
<div> | ||
<label for="age">Age:</label> | ||
<input id="age" name="age" type="number" placeholder="30" | ||
value="${contact.age}" /> | ||
</div> | ||
<button type="submit">Save</button> | ||
</form>`; | ||
} | ||
|
||
function editContactById(id) {} | ||
|
||
function deleteContactById(id) { | ||
const contacts = loadContacts(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters