Name identifies a control's key in submitted form data; value is the value sent for that control. Id has a different job: connecting elements and allowing unique references on the page. We will keep the example small, so you can see how the fields work without building a whole application first.
What You Need to Know
A control with no name is generally not included in submitted data. Checked boxes and radio buttons follow their own rules about when values are included.
Example: See It in Action
Try this markup in a fresh practice file. The next section explains the parts worth paying attention to.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<form action="/save" method="post">
<label for="nickname">Nickname</label>
<input id="nickname" name="nickname" value="Alex">
<button type="submit" name="action" value="save">Save</button>
</form>
Let’s Understand the Example
- Input creates a form control. Its type decides whether people type text, choose a date, move a slider and more.
- Label tells people what a control is for. For connects the label to the control with the matching id.
- Name is the key the browser normally sends when a form control is submitted.
- Value is the value represented or submitted by a control or data element.
- Action names the destination where the browser sends a form submission. A real server handler must exist there.
- Method controls how a form submits; GET makes values part of the URL, while POST sends them in the request body.
The browser can submit values with keys such as nickname, action. A control without a name normally contributes no entry. Whether the submission produces a result depends on the action URL and the server behind it.
What Should You See?
You should see controls for Nickname. The example uses an input of type text and sends a POST request when submitted. If the action points to a missing server endpoint, the browser cannot complete the task.
Choose one field and predict its submitted name and value. Then change the value and check whether the browser accepts it. Do not assume that a working-looking form has a real server behind it.
Try It Yourself
- Change nickname's value and identify the submitted name-value pair.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Assuming an id makes an input submit a value even without name.
- Client-side HTML validation is a helpful first check, not a security boundary. A real receiving application must validate the values again.
Key Takeaways
- Name identifies a control's key in submitted form data; value is the value sent for that control.
- Input creates a form control. Its type decides whether people type text, choose a date, move a slider and more.
- A control with no name is generally not included in submitted data. Checked boxes and radio buttons follow their own rules about when values are included.