- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input Radio type property
The HTML DOM Input radio type property is associated with the input element having its type=”radio”. It will always return radio for the input radio element.
Syntax
Following is the syntax for radio type property −
radioObject.type
Example
Let us look at an example for the radio type property −
<!DOCTYPE html> <html> <body> <h1>Input radio type Property</h1> <form> FRUIT: <input type="radio" name="fruits" id="Mango">Mango <br> </form> <p>Get the above input element type by clicking the below button</p> <button type="button" onclick="radioType()">GET Type</button> <p id="Sample"></p> <script> function radioType() { var P=document.getElementById("Mango").type; document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ; } </script> </body> </html>
Output
This will produce the following output −
On clicking the GET Type button −
We have first created an input element inside a form with type=”radio”, name=”fruits”, id=”Mango” −
<form> FRUIT: <input type="radio" name="fruits" id="Mango">Mango </form>
We then created a “GET Type” button that will execute the radioType() method when clicked by the user −
<button type=”button” onclick="radioType()">GET Type</button>
The radioType() method gets the input element using the getElementById() method and assigns its type attribute value to variable P. This variable is then displayed in the paragraph with id “Sample” using its innerHTML property −
function getType() { var P = document.getElementById("Mango").type; document.getElementById("Sample").innerHTML = "The type for the input field is : "+P; }