-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.html
More file actions
65 lines (62 loc) · 1.76 KB
/
MainPage.html
File metadata and controls
65 lines (62 loc) · 1.76 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
63
64
65
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="Styles.css" />
<title>Code Submission</title>
</head>
<body>
<div>
<h1>Javascript Code Coverage Analyzer</h1>
<form id="codeForm">
<label
for="code"
style='
font-family: "Gill Sans", "Gill Sans MT",
Calibri, Trebuchet MS", sans-serif;
'
>Enter Code:</label
>
<textarea
id="code"
name="code"
placeholder="Type your code here..."
></textarea>
<button type="submit" class="form" style="margin-left: 200px">
Submit
</button>
</form>
</div>
</body>
<script>
// Function to handle the redirect after form submission
function handleRedirect() {
console.log("Redirecting to new page");
window.location.href = "/ShowReports.html";
}
document
.getElementById("codeForm")
.addEventListener("submit", async function (event) {
event.preventDefault();
if (document.getElementById("code").value == "") {
alert("Please Enter your code");
window.reload();
} else {
try {
await fetch("http://localhost:3000/writeToFile", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
code: document.getElementById("code").value,
}),
}).then(handleRedirect());
} catch (error) {
console.error("Error submitting form:", error);
}
}
});
</script>
</html>