6. Values That Differ from Display Text
<select name="plan">
<option value="basic">Basic Plan - Free</option>
<option value="pro">Professional Plan - ₹499/month</option>
</select>The user sees the readable text, while the application receives the option's value. Server-side code must still verify that the submitted value is permitted.
7. Common Mistakes
- Using a label's for attribute that does not match the control's id.
- Assuming id automatically supplies a submitted field name.
- Giving radio buttons different names when they should be one group.
- Assuming an unchecked checkbox submits the value false.
- Trusting a submitted value just because it was generated by a dropdown.
Practice Exercises
- Build a form with correctly associated name and email labels.
- Create three radio buttons for payment method.
- Create a checkbox that is initially checked.
- Create a country dropdown with one initially selected option.
- Explain the difference between id, name and value.
Revision Quiz
- Which label attribute connects to a control's id?
- Which attribute identifies a field in submitted form data?
- Which attribute sets a checkbox's initial checked state?
- What must radio buttons share to belong to the same group?
- Which attribute sets an option as initially selected?
- Does an unchecked checkbox normally submit its value?
Answer Key and Explanations
- for — It matches the associated control's id.
- name — It identifies the submitted field.
- checked — It marks the checkbox as initially checked.
- The same name — This groups the radio buttons into one selection group.
- selected — It marks the option as initially selected.
- No. Unchecked checkboxes are normally omitted from form submission.