i need to convert this code from javascript to typescript please write like this code on type script (ts) var students = []; var selectedRow = null; function onFormSubmit() { if (validate()) { var students = readDataForm(); if (selectedRow == null) insertNewRecord(students); else updateRecord(students); resetForm(); } } function validate() { isValid = true; if (document.getElementById("name").value == "") { isValid = false; document.getElementById("nameValidationError").classList.remove("hide"); } else { isValid = true; if (!document.getElementById("nameValidationError").classList.contains("hide")) document.getElementById("nameValidationError").classList.add("hide"); } return isValid; } function resetForm() { document.getElementById("name").value = ""; document.getElementById("idNumber").value = ""; document.getElementById("gdpa").value = ""; selectedRow = null; } function readDataForm() { var students = {}; students["name"] = document.getElementById("name").value; students["idNumber"] = document.getElementById("idNumber").value; students["gdpa"] = document.getElementById("gdpa").value; return students; } function insertNewRecord(data) { var table = document.getElementById("studentList").getElementsByTagName('tbody')[0]; var newRow = table.insertRow(table.length); cell1 = newRow.insertCell(0); cell1.innerHTML = data.name; cell2 = newRow.insertCell(1); cell2.innerHTML = data.idNumber; cell3 = newRow.insertCell(2); cell3.innerHTML = data.gdpa; cell3 = newRow.insertCell(3); cell3.innerHTML = `Update Delete`; } function onUpdate(td) { selectedRow = td.parentElement.parentElement; document.getElementById("name").value = selectedRow.cells[0].innerHTML; document.getElementById("idNumber").value = selectedRow.cells[1].innerHTML; document.getElementById("gdpa").value = selectedRow.cells[2].innerHTML; } function updateRecord(students) { selectedRow.cells[0].innerHTML = students.name; selectedRow.cells[1].innerHTML = students.idNumber; selectedRow.cells[2].innerHTML = students.gdpa; } function onDelete(td) { if (confirm('Click OK if you want to delete this recording!')) { row = td.parentElement.parentElement; document.getElementById("studentList").deleteRow(row.rowIndex); resetForm(); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

i need to convert this code from javascript to typescript

please write like this code on type script (ts)

var students = [];
var selectedRow = null;
function onFormSubmit() {
if (validate()) {
var students = readDataForm();
if (selectedRow == null)
insertNewRecord(students);

else
updateRecord(students);
resetForm();
}
}

function validate() {
isValid = true;
if (document.getElementById("name").value == "") {
isValid = false;
document.getElementById("nameValidationError").classList.remove("hide");
} else {
isValid = true;
if (!document.getElementById("nameValidationError").classList.contains("hide"))
document.getElementById("nameValidationError").classList.add("hide");
}
return isValid;
}

function resetForm() {
document.getElementById("name").value = "";
document.getElementById("idNumber").value = "";
document.getElementById("gdpa").value = "";
selectedRow = null;
}


function readDataForm() {
var students = {};
students["name"] = document.getElementById("name").value;
students["idNumber"] = document.getElementById("idNumber").value;
students["gdpa"] = document.getElementById("gdpa").value;
return students;
}
function insertNewRecord(data) {
var table = document.getElementById("studentList").getElementsByTagName('tbody')[0];
var newRow = table.insertRow(table.length);
cell1 = newRow.insertCell(0);
cell1.innerHTML = data.name;
cell2 = newRow.insertCell(1);
cell2.innerHTML = data.idNumber;
cell3 = newRow.insertCell(2);
cell3.innerHTML = data.gdpa;
cell3 = newRow.insertCell(3);
cell3.innerHTML = `Update
Delete`;

}

function onUpdate(td) {
selectedRow = td.parentElement.parentElement;
document.getElementById("name").value = selectedRow.cells[0].innerHTML;
document.getElementById("idNumber").value = selectedRow.cells[1].innerHTML;
document.getElementById("gdpa").value = selectedRow.cells[2].innerHTML;
}
function updateRecord(students) {
selectedRow.cells[0].innerHTML = students.name;
selectedRow.cells[1].innerHTML = students.idNumber;
selectedRow.cells[2].innerHTML = students.gdpa;
}
function onDelete(td) {
if (confirm('Click OK if you want to delete this recording!')) {
row = td.parentElement.parentElement;
document.getElementById("studentList").deleteRow(row.rowIndex);
resetForm();
}
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY