const playgroundForm = document.getElementById("playground"); const playgroundSubmit = document.getElementById("playgroundSubmit"); const playgroundOutput = document.getElementById("playgroundOutput"); // console.log(playgroundForm.elements); playgroundSubmit.addEventListener("click", (e) => { // sorry for this let query = ""; Object.keys(playgroundForm.dataset).forEach((input) => { query += `${input}=${playgroundForm.elements[input].value}&`; }); let endpoint = `${playgroundForm.action}?${query}`; fetch(endpoint) .then(response => response.text()) .then((data) => { playgroundOutput.innerHTML = data }); });