MedhaCodes commited on
Commit
f1441cf
·
verified ·
1 Parent(s): faa58c7

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +14 -0
static/script.js CHANGED
@@ -1,9 +1,15 @@
 
1
  document.getElementById("submit-btn").addEventListener("click", async () => {
2
  const context = document.getElementById("context").value.trim();
3
  const questions = document.getElementById("question").value.trim();
4
  const output = document.getElementById("answer-box");
5
  const history = document.getElementById("history-list");
6
 
 
 
 
 
 
7
  // Clear previous answers
8
  output.innerHTML = "";
9
  output.textContent = "⏳ Generating answers...";
@@ -49,6 +55,14 @@ document.getElementById("submit-btn").addEventListener("click", async () => {
49
  // Add to history
50
  const li = document.createElement("li");
51
  li.textContent = questions.replace(/\n/g, " | ");
 
 
 
 
 
 
 
 
52
  history.prepend(li);
53
  });
54
 
 
1
+ // Submit button click
2
  document.getElementById("submit-btn").addEventListener("click", async () => {
3
  const context = document.getElementById("context").value.trim();
4
  const questions = document.getElementById("question").value.trim();
5
  const output = document.getElementById("answer-box");
6
  const history = document.getElementById("history-list");
7
 
8
+ if (!context || !questions) {
9
+ output.textContent = "⚠️ Please provide both context and question(s).";
10
+ return;
11
+ }
12
+
13
  // Clear previous answers
14
  output.innerHTML = "";
15
  output.textContent = "⏳ Generating answers...";
 
55
  // Add to history
56
  const li = document.createElement("li");
57
  li.textContent = questions.replace(/\n/g, " | ");
58
+
59
+ // Make history item clickable
60
+ li.addEventListener("click", () => {
61
+ document.getElementById("question").value = questions;
62
+ // Optionally scroll to top
63
+ document.getElementById("question").scrollIntoView({ behavior: "smooth" });
64
+ });
65
+
66
  history.prepend(li);
67
  });
68