Day 6: Exploring Forms in HTML

Shaik SharooqShaik Sharooq
2 min read

Hello everyone,

Today marks Day 6 of my full-stack development journey, and it was all about diving deeper into HTML forms. Here's what I learned:

1. The name Attribute in Forms

The name attribute is crucial when dealing with forms in HTML. It acts as the key for the form data submitted to the server. Without it, the data from the form elements wouldn't be sent or processed correctly. Here's a simple example:

    <form action="/server">
        <div>
        <label for="username">Username</label>
        <input type="text" 
        placeholder="Enter the Username" 
        id="username" 
        name = "user">
        </div>
        <div>
            <label for="password">password</label>
            <input type="password" 
            placeholder="Enter the password" 
            id="password">
        </div>

2. Checkboxes

Checkboxes allow users to select multiple options from a list. They are created using the <input type="checkbox"> element. Here’s an example:

<forms action="/check">
    <input type="checkbox" name="subjects" id="math" value="math">
    <label for="math">math</label>
    <input type="checkbox" name="subjects" id="hindi" value="hindi">
    <label for="hindi">hindi</label>
    <input type="checkbox" name="subjects" id="english" value="english">
    <label for="english">english</label>
</forms>

3. Radio Buttons

Radio buttons are used when only one option is to be selected from a group. They are created using the <input type="radio"> element. Here’s an example:

<forms action="/check">
    <input type="radio" name="fruit" id="apple" value="apple">
    <label for="apple">Apple</label>
    <input type="radio" name="fruit" id="mango" value="mango">
    <label for="mango">Mango</label>
    <input type="radio" name="fruit" id="Guava" value="Guava">
    <label for="Guava">Guava</label>
</forms>

4. Difference Between Checkboxes and Radio Buttons

The main difference between checkboxes and radio buttons is in the selection process:

  • Checkboxes allow multiple selections.

  • Radio buttons allow only one selection within a group.

5. The select Element

The select element creates a drop-down list, which allows users to choose one option from a list. It’s paired with the <option> element to define the available choices. Here’s an example:

<forms action="/check">
    Employement Status:
    <select name="Employement Status" id="emp-status">
    <option value="student">Student</option>
    <option value="employed">Employed</option>
    </select>
</forms>

Conclusion

Understanding these form elements and their attributes is essential for creating interactive and user-friendly web forms. Each element has its own specific use cases and knowing when to use them can significantly enhance the user experience on a website.

Stay tuned for more updates as I continue my journey in full-stack development!

0
Subscribe to my newsletter

Read articles from Shaik Sharooq directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaik Sharooq
Shaik Sharooq

The thrill of unraveling the complexities of programming and As a tech enthusiast, I find joy in staying up-to-date with the latest advancements in the tech industry. From artificial intelligence to sustainable infrastructure solutions, I'm eager to explore and contribute to cutting-edge innovations.