Assignment5 Js
Assignment5 Js
Assignment5 Js
"https://csunix.mohawkcollege.ca/~adams/10259/a6_responder.php";
const firstElem = document.querySelector("#first");
const contentDiv = document.querySelector("#content");
const tableDiv = document.querySelector("#content2");
const fetchBtn = document.querySelector("#b1");
const updateBtn = document.querySelector("#b2");
const submitBtn = document.querySelector("#b3");
fetchBtn.addEventListener("click", fetchDataAndDisplay);
updateBtn.addEventListener("click", () => handleButtonClick("update"));
submitBtn.addEventListener("click", () => handleButtonClick("submit"));
function updateFirstElement() {
firstElem.innerHTML = `<h1> Gaurav Patel,000898120</h1>`;
}
try {
const response = await fetch(fetchUrl);
function updateContentDiv(data) {
contentDiv.innerHTML = "";
data.forEach(item => {
const container = createContainer(item.name, item.url, item.series);
contentDiv.appendChild(container);
});
}
function updateTableDiv(data) {
tableDiv.innerHTML = "";
const createTable = document.createElement("table");
data.forEach(item => {
const rowData = [item.series, item.url, item.name];
createTable.appendChild(createRow(rowData));
});
tableDiv.appendChild(createTable);
}
function createRow(rowData) {
const row = document.createElement("tr");
rowData.forEach(content => row.innerHTML += `<td>${content}</td>`);
return row;
}
function getSelectedOption() {
const selectedInput = document.querySelector("input[name='choice']:checked");
return selectedInput ? selectedInput.value : null;
}