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 likename,id,size, andmultiple.<option>Tag: Each individual choice within the<select>element is defined by an<option>tag. It typically has avalueattribute (the data sent to the server) and displays text between its opening and closing tags.nameAttribute: Crucial for form submission, thenameattribute of the<select>tag identifies the data being sent to the server.valueAttribute: For each<option>, thevalueattribute specifies the actual data that will be sent if that option is selected. If omitted, the text content of the<option>is used.selectedAttribute: A boolean attribute added to an<option>tag to make it pre-selected when the page loads. Only one option can beselectedby default in a single-selection listbox.multipleAttribute: 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.sizeAttribute: An integer attribute for the<select>tag that specifies the number of visible options in the listbox. Ifsizeis 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 alabelattribute to provide a heading for the group.
Single vs. Multiple Selection Listboxes
- Single Selection (Default): When the
multipleattribute is absent, the listbox behaves as a standard dropdown. Users can only select one option at a time. Thesizeattribute (if greater than 1) can make it appear as a scrollable list, but still only one selection is allowed. - Multiple Selection: By adding the
multipleattribute 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.nameis vital for sending data.valuecarries the actual data of an option.multipleenables multi-select (Ctrl/Cmd click).sizecontrols visible rows.selectedmakes an option default.<optgroup>organizes options.
Practice Questions
- Which attribute of the
<select>tag defines the number of visible options without scrolling? - To send data from a listbox to the server, which attribute is essential for the
<select>tag? - What is the default behavior of a
<select>element if themultipleattribute is not specified? - Can an
<optgroup>itself be selected by a user in a listbox? - If an
<option>tag does not have avalueattribute, what data is typically submitted when that option is chosen?