Sami Bouhussein commited on
Commit
be1e2ba
·
1 Parent(s): 9c43c90

getElems by ids

Browse files
Files changed (1) hide show
  1. static/script.js +20 -18
static/script.js CHANGED
@@ -1,21 +1,23 @@
1
- const textGenForm = document.querySelector("text-gen-form");
 
2
 
3
- const translateText = async (text) => {
4
- const inferResponse = await fetch("/translate", {
5
- method: "POST",
6
- headers: { "Content-Type": "application/json" },
7
- body: JSON.stringify({ text }),
8
- });
9
- console.log("Trying to translate text");
10
- console.log(text)
11
- const inferJson = await inferResponse.json();
12
- return inferJson.translation;
13
- };
14
 
15
- textGenForm.addEventListener("submit", async (event) => {
16
- console.log("Submit bottom tapped");
17
- event.preventDefault();
18
- const textGenInput = document.getElementById("text-gen-input");
19
- const textGenParagraph = document.querySelector("text-gen-output");
20
- textGenParagraph.textContent = await translateText(textGenInput.value);
 
21
  });
 
1
+ document.addEventListener("DOMContentLoaded", () => {
2
+ const textGenForm = document.querySelector(".text-gen-form");
3
 
4
+ const translateText = async (text) => {
5
+ const inferResponse = await fetch("/translate", {
6
+ method: "POST",
7
+ headers: { "Content-Type": "application/json" },
8
+ body: JSON.stringify({ text }),
9
+ });
10
+ console.log("Trying to translate text");
11
+ console.log(text)
12
+ const inferJson = await inferResponse.json();
13
+ return inferJson.translation;
14
+ };
15
 
16
+ textGenForm.addEventListener("submit", async (event) => {
17
+ console.log("Submit bottom tapped");
18
+ event.preventDefault();
19
+ const textGenInput = document.getElementById("text-gen-input");
20
+ const textGenParagraph = document.querySelector(".text-gen-output");
21
+ textGenParagraph.textContent = await translateText(textGenInput.value);
22
+ });
23
  });