HTML forms: list MCQs Quiz | Class 10

This quiz for Class X Computer Applications (Code 165), Unit 4: Lab Exercises, focuses on HTML forms, specifically listbox selection. Test your knowledge on creating and managing single and multiple selection listboxes in HTML. After attempting the 10 multiple-choice questions, submit your answers to see your score and download a detailed answer PDF.

Understanding HTML Listboxes (Select Elements)

HTML listboxes, created using the <select> element, are essential for forms where users need to choose one or more options from a predefined list. They offer a user-friendly way to present multiple choices without cluttering the form.

Key Concepts of Listbox Selection

  • <select> Tag: This is the container for all options in a listbox. It can have attributes like name, id, size, and multiple.
  • <option> Tag: Each individual choice within the <select> element is defined by an <option> tag. It typically has a value attribute (the data sent to the server) and displays text between its opening and closing tags.
  • name Attribute: Crucial for form submission, the name attribute of the <select> tag identifies the data being sent to the server.
  • value Attribute: For each <option>, the value attribute specifies the actual data that will be sent if that option is selected. If omitted, the text content of the <option> is used.
  • selected Attribute: A boolean attribute added to an <option> tag to make it pre-selected when the page loads. Only one option can be selected by default in a single-selection listbox.
  • multiple Attribute: A boolean attribute for the <select> tag. When present, it allows users to select more than one option (typically by holding Ctrl/Cmd key). Without this, only a single option can be chosen.
  • size Attribute: An integer attribute for the <select> tag that specifies the number of visible options in the listbox. If size is greater than 1, the listbox will display as a scrollable box; otherwise, it will typically render as a dropdown menu.
  • <optgroup> Tag: Used to group related options within a <select> element. It takes a label attribute to provide a heading for the group.

Single vs. Multiple Selection Listboxes

  • Single Selection (Default): When the multiple attribute is absent, the listbox behaves as a standard dropdown. Users can only select one option at a time. The size attribute (if greater than 1) can make it appear as a scrollable list, but still only one selection is allowed.
  • Multiple Selection: By adding the multiple attribute to the <select> tag, users can choose several options. This is typically done by clicking while holding down the Ctrl (Windows/Linux) or Cmd (Mac) key.

Summary of Important Attributes for <select> and <option>

Attribute Tag Description Example Use
name <select> Name of the control, used for form submission. <select name="fruit">
id <select> Unique identifier for the element. <select id="myFruits">
multiple <select> Allows multiple options to be selected. <select multiple>
size <select> Number of visible options in the list. <select size="5">
value <option> Value to be sent to the server when selected. <option value="apple">Apple</option>
selected <option> Pre-selects an option. <option selected>Default</option>
label <optgroup> Label for the option group. <optgroup label="Fruits">

Quick Revision Checklist

  • <select> is for the whole list.
  • <option> is for individual items.
  • name is vital for sending data.
  • value carries the actual data of an option.
  • multiple enables multi-select (Ctrl/Cmd click).
  • size controls visible rows.
  • selected makes an option default.
  • <optgroup> organizes options.

Practice Questions

  1. Which attribute of the <select> tag defines the number of visible options without scrolling?
  2. To send data from a listbox to the server, which attribute is essential for the <select> tag?
  3. What is the default behavior of a <select> element if the multiple attribute is not specified?
  4. Can an <optgroup> itself be selected by a user in a listbox?
  5. If an <option> tag does not have a value attribute, what data is typically submitted when that option is chosen?

Author

  • CBSE Quiz Editorial Team

    Content created and reviewed by the CBSE Quiz Editorial Team based on the latest NCERT textbooks and CBSE syllabus. Our goal is to help students practice concepts clearly, confidently, and exam-ready through well-structured MCQs and revision content.