Lecture 5: HTML Forms From Beginner to Advance


šŸŽ„ Full Video Lecture


1. What is an HTML Form?

šŸ“– Notes:

The fundamental truth is that a website isn't just a brochure for you to read. For the web to be useful, it needs a way toĀ **collect informationĀ *from*Ā the user**Ā and send it back to the server.
Without this, you couldn't log in, search for a video, buy a product, post a comment, or send a message. The web would be a read-only library.

What is an HTML Form?

šŸŽ„ Watch:

2. input Tag

šŸ“– Notes:

This is the most common form tag. It's a self-closing tag that creates an input field. Its behavior changes based on itsĀ typeĀ attribute.
The most basic type isĀ text.

input Tag

šŸŽ„ Watch:

3. label Tag

šŸ“– Notes:

**The Problem:**Ā We have a box, but the user has no idea what they are supposed to type into it. Is it for a name? An email? A search query? The box is meaningless without a description.

**The Solution:**Ā We need to add a descriptive piece of text. The correct HTML tag for this is theĀ label. It's a tag specifically designed to be the title for a form field.

label Tag

šŸŽ„ Watch:

4. Name & Value Attributes

šŸ“– Notes:

**The Problem:**Ā When the form is submitted, the browser needs to package the data to send to a server. How does it label the data? If a user types "Arjun" in the first box, how does the server know that "Arjun" is theĀ firstName? TheĀ idĀ attribute is only for useĀ *within*Ā the page; it is not sent to the server.

**The Solution:**Ā We need another attribute whose sole purpose is to be theĀ **"data label"**Ā or theĀ **"key"**Ā for the submitted value. This is theĀ **name**Ā attribute.

Name & Value Attributes

šŸŽ„ Watch:

5. Radio Buttons

šŸ“– Notes:

**The Problem:**Ā What if you want to ask a question where the user can only chooseĀ **one option**Ā from a predefined list? For example, "What is your gender?" or "What is your T-shirt size (Small, Medium, Large)?" A text box is a bad solution—users could type anything ("Med", "M", "medium"), making the data inconsistent.

**The Solution:**Ā We need an input type where selecting one option automatically de-selects all others. This is theĀ **radio button**:Ā .

This introduces a new rule. How does the browser know which radio buttons belong to the same question?

**The Rule:**Ā All radio buttons in a single groupĀ **must share the sameĀ nameĀ attribute**. TheĀ nameĀ acts as the group identifier.

Radio Buttons

šŸŽ„ Watch:

6. checkboxes

šŸ“– Notes:

**The Problem:**Ā Now, what if you want to ask a question where the user can chooseĀ **multiple options**? For example, "Which toppings would you like on your pizza?" A radio button won't work, because you can only select one.

**The Solution:**Ā We need an input type that allows for multiple selections. This is theĀ **checkbox**:Ā input type="checkbox".

Checkboxes that are part of the same question should also share the sameĀ name. This tells the server that all the selected values belong to the same category ("toppings").

checkboxes

šŸŽ„ Watch:

7. Mini Project

Mini Project

šŸŽ„ Watch:

8. button Tag

šŸ“– Notes:

**The Problem:**Ā OurĀ Ā works, but it's very limited. You can only put plain text in it using theĀ valueĀ attribute. What if you want a button with an image, or with bold text?

**The Solution:**Ā Use theĀ 

button Tag

šŸŽ„ Watch:

9. textarea Tag

šŸ“– Notes:

**The Problem:**Ā OurĀ input type="text"Ā is great for single lines of text like a name, but it's terrible for longer input, like a user comment or a shipping address. The text just scrolls sideways and becomes unreadable.

**The Solution:**Ā We need a dedicated element for multi-line text input. This is theĀ **textarea**Ā tag.

UnlikeĀ input,Ā textareaĀ is a container tag (it has an opening and closing tag). It's also linked to aĀ labelĀ using the sameĀ forĀ andĀ idĀ pattern.

textarea Tag

šŸŽ„ Watch:

10. Homework

Homework

šŸŽ„ Watch: