The Input Checkbox type property returns/sets type of Input Checkbox.
Following is the syntax −
inputCheckboxObject.type
inputCheckboxObject.type = stringValue
Here, “stringValue” can be the following -
stringValue | Details |
---|---|
checkbox | It defines that input type is checkbox |
radio | It defines that input type is radio |
text | It defines that input type is text |
Let us see an example of Input Checkbox type property −
<!DOCTYPE html> <html> <head> <title>Type Attribute of Checkbox</title> </head> <body> <form id="Form"> <div> Other: <input id="formCheckbox" type="checkbox" name="formCheckbox"> </div> </form> <button onclick="changeType()">Change type of input</button> <div id="displayDiv"></div> <script> var typeOfInput = document.getElementById("formCheckbox"); var displayDiv = document.getElementById("displayDiv"); displayDiv.textContent = 'Type of Input: ' + typeOfInput.type function changeType(){ if(typeOfInput.type == 'checkbox'){ typeOfInput.type = 'text' displayDiv.textContent = 'Type of Input: ' + typeOfInput.type } } </script> </body> </html>
This will produce the following output −
Before clicking ‘Change type of input’ button −
After clicking ‘Change type of input’ button −