Go back

HTML Form and related tags

In this class we learnt the base of HTML forms

In this class we learnt a few more HTML tags used for input in forms

Select and option

The <select></select> and <option></option> tags work together in tandum to give us a dropdown for selection.

Example -

<select name="continent" id="continent" required>
    <option selected disabled hidden>Select your choice</option>
    <option value="africa">Africa</option>
    <option value="asia">Asia</option>
    <option value="europe">Europe</option>
    <option value="north-america">North America</option>
    <option value="south-america">South America</option>
    <option value="australia">Australia</option>
</select>

There are a few important attributes to the option tag -

Textarea

As seen before, textarea is a longer input field which can be used for longer text, especially for text with formatting and line breaks.

<textarea name="message" id="message" placeholder="Enter your message here..."></textarea>

Other lesser used input tags

Code from the class

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>More about forms</title>
</head>
<body>
    <form action="" method="get">
        <label for="name">Select your continent</label>
        <select name="continent" id="continent" required>
            <option selected disabled hidden>Select your choice</option>
            <option value="africa">Africa</option>
            <option value="asia">Asia</option>
            <option value="europe">Europe</option>
            <option value="north-america">North America</option>
            <option value="south-america">South America</option>
            <option value="australia">Australia</option>
        </select>
        <textarea name="message" id="message" placeholder="Enter your message here..."></textarea>
        <input type="date" id="date" name="date" min="2024-01-01" max="2025-08-18">
        <input type="time" id="time" name="time">
        <input type="datetime-local" id="datetime" name="datetime">
        <input type="range" name="range" id="range" min="0" max="5" step="0.5" value="4">
        <div id="rangevalue"></div>
        <input type="color" name="color" id="color">
        
        <input type="file" name="picture" id="picture" accept="document/word">
        
        <input type="submit" value="Submit">
        <input type="reset" value="reset">
        
        
        <button type="reset">Reset</button>

    </form>
    <a href="#section2">Go to Section 2</a>
    <div id="section1" style="height: 100vh">
        <h2>Form Data</h2>
        <p id="formData"></p>
    </div>
    <div id="section2" style="height: 100vh; background-color: red;">
        <h2>Form Data</h2>
        <p id="formData"></p>
    </div>
    <script>
        document.getElementById("range").addEventListener("input", function() {
            document.getElementById("rangevalue").innerText = this.value;
        });
    </script>
</body>
</html>