abhattac commited on
Commit
74dfba9
·
1 Parent(s): 91ec962

added event listener

Browse files
Files changed (1) hide show
  1. index.html +13 -12
index.html CHANGED
@@ -10,7 +10,7 @@
10
  <div class="card">
11
  <h1>Welcome to my GPT test environment!</h1>
12
  <p>Enter a prompt in the textbox to get started</p>
13
- <textarea name="prompt" id="prompt" cols="30" rows="10"></textarea>
14
  <button id="submit">Submit</button>
15
  <p id="response"></p>
16
  </div>
@@ -20,16 +20,17 @@
20
  const textbox = document.querySelector("#prompt")
21
  const res = document.querySelector("#response")
22
  const prompt = textbox.value
23
- fetch(`/gpt?prompt=${prompt}`)
24
- .then(res => res.json())
25
- .then(res => {
26
- console.log(res)
27
- res.textContent = "success"
28
- })
29
- .catch(err => {
30
- console.log(err)
31
- res.textContent = "failure"
32
- })
33
-
 
34
  </script>
35
  </html>
 
10
  <div class="card">
11
  <h1>Welcome to my GPT test environment!</h1>
12
  <p>Enter a prompt in the textbox to get started</p>
13
+ <textarea name="prompt" id="prompt" cols="30" rows="10"></textarea><br>
14
  <button id="submit">Submit</button>
15
  <p id="response"></p>
16
  </div>
 
20
  const textbox = document.querySelector("#prompt")
21
  const res = document.querySelector("#response")
22
  const prompt = textbox.value
23
+ btn.on("click", event => {
24
+ fetch(`/gpt?prompt=${prompt}`)
25
+ .then(res => res.json())
26
+ .then(res => {
27
+ console.log(res)
28
+ res.textContent = res
29
+ })
30
+ .catch(err => {
31
+ console.log(err)
32
+ res.textContent = err
33
+ })
34
+ })
35
  </script>
36
  </html>