
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input Checkbox required Property
The Input Checkbox required property determines whether Input Checkbox is compulsory to check or not.
Syntax
Following is the syntax −
- Returning boolean value - true/false
inputCheckboxObject.required
- Setting required to booleanValue
inputCheckboxObject.required = booleanValue
Boolean Values
Here, “booleanValue” can be the following −
booleanValue | Details |
---|---|
true | It defines that it is compulsory to check the checkbox to submit form. |
false | It is the default value and checking is not compulsory. |
Example
Let us see an example of Input Checkbox required property −
<!DOCTYPE html> <html> <head> <title>Required Attribute of Checkbox</title> </head> <body> <form id="Form"> <div> Check me ! I am required: <input id="formCheckbox" type="checkbox" name="formCheckbox" required> </div> </form> <button onclick="getRequiredStatus()">Check if form is submittable</button> <div id="displayDiv"></div> <script> function getRequiredStatus(){ var requiredBool = document.getElementById("formCheckbox"); var displayDiv = document.getElementById("displayDiv"); if(requiredBool.required == false || (requiredBool.required == true && requiredBool.checked == true)){ displayDiv.textContent = 'Required attribute of checkbox: '+requiredBool.required + ', form is submittable '; } else { displayDiv.textContent = 'Check the checkbox'+ ', current value of required attribute: '+requiredBool.required ; } } </script> </body> </html>
Output
This will produce the following output −
Clicking ‘Check if form is submittable’ button with unchecked checkbox −
After clicking ‘Check if form is submittable’ button with checked checkbox −
- Related Articles
- HTML DOM Input Checkbox checked Property
- HTML DOM Input Checkbox defaultChecked Property
- HTML DOM Input Checkbox autofocus Property
- HTML DOM Input Checkbox disabled Property
- HTML DOM Input Checkbox form Property
- HTML DOM Input Checkbox name Property
- HTML DOM Input Checkbox type Property
- HTML DOM Input Checkbox value Property
- HTML DOM Input FileUpload required Property
- HTML DOM Input Month required Property
- HTML DOM Input Number required Property
- HTML DOM Input Radio required property
- HTML DOM Input Password required property
- HTML DOM Input Date required Property
- HTML DOM Input Datetime required Property

Advertisements