Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I created an address book where the user enters the name, phone and email in the input field. This is stored in a array/ list

I created an address book where the user enters the name, phone and email in the input field. This is stored in a array/ list that adds up and shows it in a table below.

how can I use a button to sort the list based on name, telephone or email?

i have example inputs in the table/array and the user can add more contacts as well, so it needs to work for both of them.

here's my code:

HTML:

Add entry

Name Tel Email

Javascript:

var Rows = null

function Form() {

var formData = readFormData();

if (Rows == null)

insertNewRecord(formData);

else

updateRecord(formData);

resetForm();

}

function readFormData() {

var formData = [];

formData["name"] = document.getElementById("name").value;

formData["tel"] = document.getElementById("tel").value;

formData["email"] = document.getElementById("email").value;

return formData;

}

function insertNewRecord(data) {

var table = document.getElementById("MyList").getElementsByTagName('tbody')[0];

var newRow = table.insertRow(table.length);

cell1 = newRow.insertCell(0);

cell1.innerHTML = data.name;

cell2 = newRow.insertCell(1);

cell2.innerHTML = data.tel;

cell3 = newRow.insertCell(2);

cell3.innerHTML = data.email;

cell4 = newRow.insertCell(3);

cell4.innerHTML = `Edit

Delete`;

}

function insert(){

var table = document.getElementById("MyList").getElementsByTagName('tbody')[0];

var newRow = table.insertRow(table.length);

cell1 = newRow.insertCell(0);

cell1.innerHTML = "Nina";

cell2 = newRow.insertCell(1);

cell2.innerHTML = "48569244";

cell3 = newRow.insertCell(2);

cell3.innerHTML = "example";

cell4 = newRow.insertCell(3);

cell4.innerHTML = `Edit

Delete`;

var newRow = table.insertRow(table.length);

cell1 = newRow.insertCell(0);

cell1.innerHTML = "harald";

cell2 = newRow.insertCell(1);

cell2.innerHTML = "98569144";

cell3 = newRow.insertCell(2);

cell3.innerHTML = "example email";

cell4 = newRow.insertCell(3);

cell4.innerHTML = `Edit

Delete`;

var newRow = table.insertRow(table.length);

cell1 = newRow.insertCell(0);

cell1.innerHTML = "susanne";

cell2 = newRow.insertCell(1);

cell2.innerHTML = "45625894";

cell3 = newRow.insertCell(2);

cell3.innerHTML = "example mail";

cell4 = newRow.insertCell(3);

cell4.innerHTML = `Edit

Delete`;

}

function resetForm() {

document.getElementById("name").value = "";

document.getElementById("tel").value = "";

document.getElementById("email").value = "";

selectedRow = null;

}

function Edit(td) {

selectedRow = td.parentElement.parentElement;

document.getElementById("name").value = selectedRow.cells[0].innerHTML;

document.getElementById("tel").value = selectedRow.cells[1].innerHTML;

document.getElementById("email").value = selectedRow.cells[2].innerHTML;

}

function updateRecord(formData) {

selectedRow.cells[0].innerHTML = formData.name;

selectedRow.cells[1].innerHTML = formData.tel;

selectedRow.cells[2].innerHTML = formData.email;

}

function Delete(td) {

if (confirm('Do you want to delete it?')) {

row = td.parentElement.parentElement;

document.getElementById("MyList").deleteRow(row.rowIndex);

resetForm();

}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 Tsukuba Japan April 2010 Proceedings Part 1 Lncs 5981

Authors: Hiroyuki Kitagawa ,Yoshiharu Ishikawa ,Wenjie Li ,Chiemi Watanabe

2010th Edition

3642120253, 978-3642120251

More Books

Students also viewed these Databases questions

Question

Prove that a red-black tree with n nodes has (n) black nodes.

Answered: 1 week ago

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago

Question

7. Define cultural space.

Answered: 1 week ago