-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (51 loc) · 1.91 KB
/
script.js
File metadata and controls
62 lines (51 loc) · 1.91 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Store the server's IP address in a variable
const serverIP = "192.168.1.7";
// Function to submit user data to the server
function submitData() {
const name = document.getElementById("name").value;
const prn = document.getElementById("prn").value;
const division = document.getElementById("division").value;
// Validate that Name, PRN, and Division are not empty
if (name.trim() === "" || prn.trim() === "" || division.trim() === "") {
alert("Please fill in all the required fields.");
return;
}
const assignmentCheckboxes = document.querySelectorAll(
'input[name="assignment"]:checked'
);
const assignments = Array.from(assignmentCheckboxes)
.map((checkbox) => checkbox.value)
.join(", ");
const data = `\nName: ${name}\nPRN: ${prn}\nDivision: ${division}\nAssignments: ${assignments}`;
fetch(`http://${serverIP}:8080`, {
method: "POST",
body: data,
})
.then((response) => response.text())
.then((message) => {
alert(message);
})
.catch((error) => console.error("Error:", error));
}
// Simple JavaScript code to fetch data from the server
fetch(`http://${serverIP}:8080`)
.then((response) => response.text())
.then((data) => {
document.getElementById("activityData").textContent = data;
// Parse the data and populate the table
const entries = data.trim().split("\n\n");
const tableBody = document.querySelector("#dataTable tbody");
tableBody.innerHTML = ""; // Clear existing rows
entries.forEach((entry) => {
const rows = entry.split("\n");
const newRow = tableBody.insertRow();
rows.forEach((row) => {
const [header, value] = row.split(": ");
const cellElement = newRow.insertCell();
cellElement.textContent = value;
});
// Add a line break after each entry
tableBody.appendChild(document.createElement("br"));
});
})
.catch((error) => console.error("Error:", error));