From dd843f687bc90c39a36497c5c28c3f9e38562b8b Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Sat, 10 Oct 2020 12:05:53 +0200 Subject: Dynamic question loading --- profile/public/script.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'profile/public/script.js') diff --git a/profile/public/script.js b/profile/public/script.js index e69de29..7c72b69 100644 --- a/profile/public/script.js +++ b/profile/public/script.js @@ -0,0 +1,14 @@ +const fs = document.querySelector("fieldset"); + +function appendQuestions(question) { + const field = document.createElement("input"); + field.name = question.id; + field.value = question.answer ?? ""; + field.placeholder = question.question; + fs.insertBefore(field, fs.querySelector("button")); +} + +fetch("api/questions") + .then((response) => response.json()) + .then((response) => response.forEach(appendQuestions)) + .catch(console.error); -- cgit v1.2.3