Untitled

 avatar
unknown
plain_text
9 months ago
1.0 kB
17
Indexable

document.addEventListener("DOMContentLoaded", () => {
  const form = document.getElementById("filterForm");
  const selects = form.querySelectorAll("select");
  const checkboxes = form.querySelectorAll('input[type="checkbox"]');
  const hidden = document.getElementById("last_changed");

  function submitForm(changedName) {
    hidden.value = changedName;

    // Build form data (invisible to URL)
    const formData = new FormData(form);

    fetch("/submit/", {
      method: "POST",
      body: formData,
    })
      .then((res) => res.text())
      .then((html) => {
        // Replace current page with updated filters/results
        document.open();
        document.write(html);
        document.close();
      })
      .catch((err) => console.error("Dynamic submit failed:", err));
  }

  // Dropdowns
  selects.forEach((select) => {
    select.addEventListener("change", () => submitForm(select.name));
  });

  // Checkboxes
  checkboxes.forEach((cb) => {
    cb.addEventListener("change", () => submitForm(cb.name));
  });
});

Editor is loading...
Leave a Comment