apply required attribute to checkbox

45 Views Asked by At

can we apply required attribute to checkbox in html multiple checkbox?without use of javascript or jquery

I want to apply validation to html page without javascript.and warning message also be shown.answer don't contain any type of function etc.

2

There are 2 best solutions below

7
Kuno van Noort On

I'm pretty sure it can be done with:

<!-- other code here -->
<input type="checkbox" required>
<!-- other code here -->

This will automatically give an error popup message if the checkbox is not filled in.

2
Suryateja KONDLA On

Yes, you can apply the required attribute to a checkbox in HTML, even when you have multiple checkboxes.

<form>
    <div>
        <label><input type="checkbox" name="option" value="option1" required> Option 1</label>
    </div>
    <div>
        <label><input type="checkbox" name="option" value="option2" required> Option 2</label>
    </div>
    <div>
        <label><input type="checkbox" name="option" value="option3" required> Option 3</label>
    </div>
    <div>
        <label><input type="checkbox" name="option" value="option4" required> Option 4</label>
    </div>

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