diff options
author | Marvin Borner | 2020-10-02 21:12:23 +0200 |
---|---|---|
committer | Marvin Borner | 2020-10-02 21:12:23 +0200 |
commit | e52bcb760f36b68495692ac5c5a5b68e8dafc33b (patch) | |
tree | 9e386b6081a0516d2c475e187f0b744d65aae156 /poll/public/script.js | |
parent | 762794cecdb0b12b58db0de16d31c8d7c216171c (diff) |
Added polls
Diffstat (limited to 'poll/public/script.js')
-rw-r--r-- | poll/public/script.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/poll/public/script.js b/poll/public/script.js new file mode 100644 index 0000000..a42777f --- /dev/null +++ b/poll/public/script.js @@ -0,0 +1,40 @@ +const dropdown = document.getElementById("answer"); +const question_input = document.getElementById("question"); +const question_label = document.getElementById("question_label"); + +dropdown.insertAdjacentHTML("beforeend", '<option selected="true" disabled>Schüler/in auswählen...</option>'); + +function appendOption(response) { + response.forEach((elem) => { + dropdown.insertAdjacentHTML( + "beforeend", + `<option value="${elem["id"]}">${elem["name"]} ${elem["middlename"] ? elem["middlename"] : " "}${ + elem["surname"] + }</option>` + ); + }); +} + +function appendQuote(response) { + response.forEach((elem) => { + document + .getElementById(elem["class"]) + .insertAdjacentHTML( + "beforeend", + `<li>${elem["name"]} ${elem["middlename"] ? elem["middlename"] : " "}${elem["surname"]}: ${ + elem["quote"] + }</li>` + ); + }); +} + +fetch("/auth/api/list") + .then((response) => response.json()) + .then((response) => appendOption(response)); + +fetch("/poll/api/get") + .then((response) => response.json()) + .then((response) => { + question_label.innerText = response["question"]; + question_input.setAttribute("value", response["id"]); + }); |