Suggest an editImprove this articleRefine the answer for “What does name do on a form field?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**The `name` attribute** on a form field defines the variable name under which the browser sends that field's value to the server when the form is submitted. It works like the key in a "key = value" pair, where `name` is the key and the value entered by the user is the data attached to it. **Key point:** without a `name` attribute, a field will not be included in the request at all; the server simply will not know the user entered anything.Shown above the full answer for quick recall.Answer (EN)ImageThe `name` attribute on a form field defines **the variable name** under which the browser **sends that field's value to the server** when the form is submitted. It works like a **key in a "key = value" pair**, where `name` is the key, and the value entered by the user is the data attached to it. --- ### 1. Example ```html <form action="/submit" method="post"> <input type="text" name="username" value="Oleh"> <input type="password" name="password" value="12345"> <button type="submit">Log in</button> </form> ``` On submission, the browser sends the data to the server like this: ```javascript username=Oleh&password=12345 ``` That is: - `name="username"` -> key `"username"`, - `value="Oleh"` -> value `"Oleh"`. --- ### 2. Without name, the data is not sent If a field **has no `name` attribute**, it **does not end up in the request**; the server simply will not know the user entered anything. Example: ```html <input type="text" placeholder="Name"> ``` Even if the user types text, it **will not be sent** when the form is submitted. --- ### 3. How it works - The browser collects every form element that has `name`; - it builds `name=value` pairs; - it joins them into a string and sends it to the server via `GET` or `POST`. Example with a checkbox: ```html <input type="checkbox" name="subscribe" value="yes" checked> ``` On submission: ```javascript subscribe=yes ``` --- ### 4. Interaction with JavaScript The `name` attribute makes it easy to read field values: ```html <form id="form"> <input type="text" name="email" value="test@example.com"> </form> <script> const email = document.forms["form"]["email"].value; console.log(email); // "test@example.com" </script> ``` --- ### 5. When name matters most | Element | Why name is needed | |---|---| | `<input>` | To send the entered value | | `<textarea>` | To pass the text | | `<select>` | To send the chosen option | | `<input type="radio">` | To group them together | | `<input type="checkbox">` | To identify the chosen item | --- ### Summary: | Parameter | Value | |---|---| | Attribute | `name` | | Purpose | Sets the field name when sending data | | What it does | Links the field's value to a key on submission | | Without it | The data will not end up in the request | | Applies to | Any form elements (`input`, `textarea`, `select`) | --- **In simple terms:** `name` is a **"tag" for a field** that lets the server understand which data belongs to what. If a form is a questionnaire, then `name` is **the name of a row on that questionnaire**, and the value entered by the user is the **answer to that question**.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.