Lesson 2.4 β Select Menu & Text Areas
π Creating Dropdown Menus and Multi-Line Input Fields in HTML Forms
π― Learning Objectives
After completing this lesson, students will be able to:
β Understand Select Menus
β Create Dropdown Lists
β Add Multiple Options
β Understand Text Areas
β Create Multi-Line Input Fields
β Build Professional Forms
β Create Admission and Feedback Forms
π Introduction
Imagine a College Admission Form.
For Branch Selection:
Computer Science
Mechanical
Civil
Electrical
Electronics
Should we create:
<input type="text">
β No
Student may enter incorrect values.
Instead we use:
π Dropdown Menu
Another Example:
Feedback Form
Write your Suggestions
Should we use:
<input type="text">
β No
Because feedback can be several lines long.
Instead we use:
π Text Area
π What is a Select Menu?
A Select Menu creates a dropdown list.
It allows users to choose one option from many options.
Real Life Examples
Branch Selection
βΌ Computer Science
Country Selection
βΌ India
Blood Group Selection
βΌ O+
π― Select Tag
Dropdown menus are created using:
<select>
Options are created using:
<option>
Basic Syntax
<select>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
Example
<label>Branch:</label>
<select>
<option>Computer Science</option>
<option>Mechanical</option>
<option>Civil</option>
<option>Electrical</option>
</select>
Output
Branch:
βΌ Computer Science
When clicked:
Computer Science
Mechanical
Civil
Electrical
π Value Attribute
Professional forms use values.
Example:
<option value="CSE">
Computer Science
</option>
Example
<select>
<option value="CSE">
Computer Science
</option>
<option value="ME">
Mechanical
</option>
<option value="CE">
Civil
</option>
</select>
Why Use Value?
When submitted:
CSE
is stored instead of the full text.
π― Selected Attribute
Sets a default option.
Example
<option selected>
Computer Science
</option>
Result
Computer Science appears automatically.
Example
<select>
<option selected>
Computer Science
</option>
<option>
Mechanical
</option>
<option>
Civil
</option>
</select>
π Grouping Options
Large dropdowns can be grouped using:
<optgroup>
Example
<select>
<optgroup label="Engineering">
<option>CSE</option>
<option>Mechanical</option>
</optgroup>
<optgroup label="Management">
<option>BBA</option>
<option>MBA</option>
</optgroup>
</select>
Output
Engineering
CSE
Mechanical
Management
BBA
MBA
π What is a Text Area?
A Text Area allows users to enter:
Multiple Lines of Text
Real Life Examples
Feedback
Suggestions
Address
Description
Comments
Textarea Tag
Created using:
<textarea>
Basic Syntax
<textarea>
</textarea>
Example
<label>Address:</label>
<textarea>
</textarea>
Output
Large input box appears.
π― Rows Attribute
Controls height.
Example
<textarea rows="5">
</textarea>
Meaning
5 lines high.
π― Cols Attribute
Controls width.
Example
<textarea
rows="5"
cols="30">
</textarea>
Meaning
30 character width.
Example
<label>Address:</label>
<br>
<textarea
rows="5"
cols="30">
</textarea>
Output
βββββββββββββββββββββββ
β β
β β
β β
β β
β β
βββββββββββββββββββββββ
π Placeholder in Textarea
Example:
<textarea
placeholder="Enter your address">
</textarea>
Output
Enter your address
appears inside the box.
π Complete Example
<!DOCTYPE html>
<html>
<head>
<title>Select and Textarea</title>
</head>
<body>
<h1>Student Form</h1>
<form>
<label>Branch:</label>
<br>
<select>
<option>
Computer Science
</option>
<option>
Mechanical
</option>
<option>
Civil
</option>
<option>
Electrical
</option>
</select>
<br><br>
<label>Address:</label>
<br>
<textarea
rows="5"
cols="30">
</textarea>
</form>
</body>
</html>
π― Expected Output
Branch
Dropdown Menu
Address
Large Text Area
π« Real World Example β College Admission Form
<form>
<label>Branch:</label>
<br>
<select>
<option>
Computer Science
</option>
<option>
Mechanical
</option>
<option>
Civil
</option>
</select>
<br><br>
<label>Address:</label>
<br>
<textarea
rows="4"
cols="30">
</textarea>
</form>
π Real World Example β Feedback Form
<form>
<label>Your Feedback:</label>
<br>
<textarea
rows="6"
cols="40"
placeholder="Write your feedback here">
</textarea>
</form>
π― Combining Input, Radio, Checkbox, Select and Textarea
<form>
<label>Name:</label>
<input type="text">
<br><br>
<label>Gender:</label>
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female
<br><br>
<label>Skills:</label>
<input type="checkbox"> HTML
<input type="checkbox"> CSS
<br><br>
<label>Branch:</label>
<select>
<option>CSE</option>
<option>Mechanical</option>
</select>
<br><br>
<label>Address:</label>
<textarea rows="4" cols="30"></textarea>
</form>
π» Complete Practical Program
<!DOCTYPE html>
<html>
<head>
<title>College Admission Form</title>
</head>
<body>
<h1>College Admission Form</h1>
<form>
<label>Student Name:</label>
<br>
<input type="text">
<br><br>
<label>Branch:</label>
<br>
<select>
<option>Computer Science</option>
<option>Mechanical</option>
<option>Civil</option>
<option>Electrical</option>
</select>
<br><br>
<label>Address:</label>
<br>
<textarea
rows="5"
cols="30">
</textarea>
</form>
</body>
</html>
β οΈ Common Beginner Mistakes
Mistake 1
Using Input Instead of Select
Wrong:
<input type="text">
for branch selection.
Correct:
<select>
<option>CSE</option>
</select>
Mistake 2
Using Input Instead of Textarea
Wrong:
<input type="text">
for feedback.
Correct:
<textarea>
</textarea>
Mistake 3
Forgetting Option Tags
Wrong:
<select>
CSE
Mechanical
</select>
Correct:
<select>
<option>CSE</option>
<option>Mechanical</option>
</select>
π Best Practices
β Use Select for predefined choices.
β Use Textarea for long text.
β Use placeholders for guidance.
β Keep dropdown options organized.
β Use meaningful labels.
π Mini Project β Student Feedback Form
Create:
Branch Selection
Dropdown Menu
Semester Selection
Dropdown Menu
Feedback
Text Area
Suggestions
Text Area
π Practical Activity
Create a form containing:
β Name
β Branch Dropdown
β Semester Dropdown
β Address Textarea
β Feedback Textarea
Run it in Chrome Browser.
π Assignment
Assignment 2.4
- What is a Select Menu?
- Which tag creates a dropdown list?
- Which tag creates options?
- What is a Text Area?
- Which tag creates a text area?
- What is the purpose of rows and cols?
- Create a simple feedback form.
π§ Quiz
Q1. Which tag creates a dropdown menu?
A. <option>
B. <select>
C. <input>
D. <list>
β Answer: B
Q2. Which tag creates dropdown options?
A. <item>
B. <choice>
C. <option>
D. <menu>
β Answer: C
Q3. Which tag creates a multi-line input field?
A. <input>
B. <text>
C. <textarea>
D. <area>
β Answer: C
Q4. Which attribute controls textarea height?
A. cols
B. height
C. rows
D. size
β Answer: C
Q5. Which attribute controls textarea width?
A. rows
B. cols
C. width
D. size
β Answer: B
π Lesson Summary
β
<select> creates dropdown menus.
β
<option> creates menu options.
β
<textarea> creates multi-line input fields.
β Rows control height.
β Cols control width.
β Dropdowns are used for predefined choices.
β Textareas are used for addresses, feedback, and comments.