Content · Web Development · HTML

HTML DOM FormData: Reading Submitted Controls

DOM FormData: Reading Submitted Controls: The result depends on browser support and, in examples with script elements, on JavaScript being allowed. Includes a practical HTML example and an explanation.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

A useful interface does not need to be complicated. Start with native HTML, then add JavaScript only when you need it.

What You Need to Know


FormData collects successful named form controls into name/value entries. It does not invent values for unchecked checkboxes, and disabled controls are normally excluded.

In this example: read the values of a contact form.

Try the Example


Take a look at the example. We’ll explain the important lines right below it.

<form id="contact-form">
    <label for="visitor-name">Name</label>
    <input id="visitor-name" name="visitor-name" value="Alex">
    <button type="submit">Inspect data</button>
</form>
<script>
    const contactForm = document.querySelector("#contact-form");
    contactForm.addEventListener("submit", (event) => {
        event.preventDefault();
        const formValues = new FormData(contactForm);
        console.log(formValues.get("visitor-name"));
    });
</script>

Let’s Read the Code


  • <form>: The form groups controls and identifies where submitted data goes.
  • <label>: The label tells people what the input is for. A matching for/id pair makes the label clickable.
  • id: An id uniquely identifies an element on this page.
  • for: For connects a label or output with a control by ID.

Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.

What Happens in the Browser?


When this example includes JavaScript, it supplies behavior that ordinary HTML does not automatically provide. Always think about a fallback.

What makes it interactive? Look for the JavaScript that finds an element and reacts to an event. HTML provides the initial controls and content; the script updates the page. Try removing the script to see which part still works natively.

Your Turn


Run this on a local development server if it loads modules or resources. Change the visible text or trigger and check what still works with scripts disabled.

Common Beginner Mistakes


  • Assuming new HTML syntax works in every browser without testing.
  • HTML supplies structure; JavaScript is necessary for the scripted behavior in this example. Check keyboard access and focus movement too.

Key Takeaways


  • FormData collects successful named form controls into name/value entries.
  • <form>: The form groups controls and identifies where submitted data goes.
  • Remember that HTML form rules help the visitor, but server-side code must decide whether received data is valid.
Share this resourceSend this page to someone who may find it useful.