INPUT checkbox type

 INPUT checkbox type

The `<input>` element with `type="checkbox"` is used to create a checkbox in HTML.

 Syntax:

<input type="checkbox" name="checkboxName" value="checkboxValue" id="checkboxId">

<label for="checkboxId">Checkbox Label</label>

 - `type="checkbox"`: Specifies that the input should be rendered as a checkbox.
- `name="checkboxName"`: Specifies the name attribute, which is used when submitting the form to identify the checkbox.
- `value="checkboxValue"`: Specifies the value that will be sent to the server if the checkbox is checked and the form is submitted.
- `id="checkboxId"`: Provides a unique identifier for the checkbox, which is associated with the `<label>` using the `for` attribute.

  Example:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Checkbox Example</title>

</head>

<body>

    <form action="process_form.php" method="post">

        <input type="checkbox" name="subscribe" value="yes" id="subscribeCheckbox">

        <label for="subscribeCheckbox">Subscribe to newsletter</label>

 

        <input type="checkbox" name="agreeTerms" value="yes" id="agreeTermsCheckbox">

        <label for="agreeTermsCheckbox">I agree to the terms and conditions</label>

 

        <input type="submit" value="Submit">

    </form>

</body>

</html>

 

In this example:

- Two checkboxes are created with the names "subscribe" and "agree terms."
- When the form is submitted, the value "yes" will be sent to the server for the checked checkboxes.
- Each checkbox is associated with a `<label>` for better accessibility and user experience. The `for` attribute of the `<label>` corresponds to the `id` attribute of the associated checkbox.

------------------------------------------------------------------------------------------------

Post a Comment

0 Comments