const e_user_selected = document.getElementById("user-selected"); let current; document.querySelectorAll("#users tr").forEach((el) => { el.addEventListener("click", () => { current = el.querySelector("td:nth-child(2)").textContent; e_user_selected.textContent = current; }); }); document.querySelectorAll("button").forEach((el) => { el.addEventListener("click", (ev) => { if (!current) { ev.preventDefault(); return; }; const e = el.parentElement; e.setAttribute("action", el.parentElement.dataset.url.replaceAll("{}", current)); }); });