Repository navigation
Expand file tree
/
Copy pathupload.html
More file actions
87 lines (75 loc) · 3.04 KB
/
Copy pathupload.html
File metadata and controls
87 lines (75 loc) · 3.04 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Paper</title>
<link rel="stylesheet" href="styles.css">
<style>
h2{
color: whitesmoke;
}
</style>
</head>
<body>
<header>
<h1>Exam Paper Generator</h1>
</header>
<main>
<h2>Upload Paper</h2>
<!-- Wrap textarea and button inside a form -->
<form method="POST" action="/upload">
<textarea id="upload-area" name="questions" placeholder="Paste or type your questions here..." rows="20" cols="80"></textarea>
<br>
<button type="submit" id="submit-upload">Submit</button>
</form>
<a href="/"><button>Back to Home Page</button></a>
</main>
<script>
// Ensure the script runs after the DOM is fully loaded
document.addEventListener("DOMContentLoaded", function () {
// Handle Submit Button
const submitButton = document.getElementById("submit-upload");
if (submitButton) {
submitButton.addEventListener("click", function (event) {
event.preventDefault(); // Prevent default form submission
const uploadedQuestions = document.getElementById("upload-area").value.trim();
if (uploadedQuestions === "") {
alert("Please paste or type some questions before submitting!");
return;
}
// Send the question to the backend using Fetch API
fetch("/upload", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: `questions=${encodeURIComponent(uploadedQuestions)}`,
})
.then((response) => {
if (response.ok) {
return response.text();
} else {
throw new Error("Failed to upload questions.");
}
})
.then((data) => {
alert(data); // Display server response
document.getElementById("upload-area").value = ""; // Clear the textarea
})
.catch((error) => {
alert(error.message);
});
});
}
// Handle Back to Home Button
const backHomeButton = document.getElementById("back-home");
if (backHomeButton) {
backHomeButton.addEventListener("click", function () {
window.location.href = "index.html"; // Navigate back to the home page
});
}
});
</script>
</body>
</html>