send.webforms.toRead the docs →

AJAX contact form (no page reload)

The default form POST navigates away, which is fine until the form lives in a modal, a sidebar, or halfway down a landing page you do not want to lose. This version submits with fetch and swaps the form for a success message in place. The unglamorous parts - disabling the button during submit, showing a real error on failure - are included, because they are the difference between a demo and something you ship.

Copy-paste HTML

index.html
<form id="contact-form" action="https://send.webforms.to/wft_your_key" method="POST">
  <label for="name">Name</label>
  <input id="name" name="name" type="text" required>

  <label for="email">Email</label>
  <input id="email" name="email" type="email" required>

  <label for="message">Message</label>
  <textarea id="message" name="message" required></textarea>

  <button type="submit">Send</button>
  <p id="form-status" role="status" aria-live="polite"></p>
</form>

<script>
  const form = document.getElementById("contact-form");
  const status = document.getElementById("form-status");

  form.addEventListener("submit", async (e) => {
    e.preventDefault();
    const button = form.querySelector("button");
    button.disabled = true;
    status.textContent = "Sending...";

    try {
      const res = await fetch(form.action, {
        method: "POST",
        body: new FormData(form),
        headers: { Accept: "application/json" },
      });

      if (res.ok) {
        form.reset();
        status.textContent = "Thanks - your message is on its way.";
      } else {
        status.textContent = "Something went wrong. Please try again.";
      }
    } catch {
      status.textContent = "Network error. Check your connection and retry.";
    } finally {
      button.disabled = false;
    }
  });
</script>

Replace https://send.webforms.to/wft_your_key with your own endpoint from the WebForms dashboard.

Why these fields

Where to send it

Get your endpoint

Free for 300 submissions a month. No card required.

Start free

AJAX contact form FAQ

For one form, sixty lines of vanilla JS beats a dependency. Libraries earn their keep on multi-step or heavily validated forms, not a contact form.