
- 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 Radio value Property
The HTML DOM Input radio value property is associated with the input element having type=”radio” and the value attribute. It is used to return the value of radio button value attribute or to set it.
The value property for radio button doesn’t affect the user interface of the website as the content is simply not displayed. However it can be used to distinguish between several buttons of the same group when the form is submitted.
Syntax
Following is the syntax for −
Set the value property −
radioObject.value = text;
Here, text is used for specifying the value for the radio button.
Example
Let us look at an example for the input radio value property −
<!DOCTYPE html> <html> <body> <h1>Input radio Value property</h1> <form> FRUIT: <input type="radio" name="fruits" id="BTN1" value="Mango" >Mango <br> </form> <p>Get the above element value by clicking the below button</p> <button type=”button” onclick="getValue()">Get Value</button> <p id="Sample"></p> <script> function getValue() { var t = document.getElementById("BTN1").value; document.getElementById("Sample").innerHTML = "The value for the radio button is : "+t; } </script> </body> </html>
Output
This will produce the following output −
On clicking the “Get Value” button −
In the above example −
We have first created an input element inside a form with type=”radio”, name=”fruits”, id=”BTN1” and value “Mango” −
<form> FRUIT: <input type="radio" name="fruits" id=”BTN1" value=”mango>Mango </form>
We then created a “GET Type” button that will execute the radioType() method on being clicked by the user −
<button type=”button” onclick="radioType()">GET Type</button>
The getValue() method gets the input element using the getElementById() method and assigns its “value” attribute value to variable t. It will return an empty sting if the value attribute has not been specified for the radio button.This variable is then displayed in the paragraph with id “Sample” using its innerHTML property −
function getValue() { var t = document.getElementById("PASS1").value; document.getElementById("Sample").innerHTML = "The value for the input field is : "+t; }
- Related Articles
- HTML DOM Input Radio autofocus property
- HTML DOM Input Radio checked Property
- HTML DOM Input Radio defaultChecked Property
- HTML DOM Input Radio disabled Property
- HTML DOM Input Radio form Property
- HTML DOM Input Radio name Property
- HTML DOM Input Radio required property
- HTML DOM Input Radio type property
- HTML DOM Input Radio object
- HTML DOM Input Time value Property
- HTML DOM Input URL value Property
- HTML DOM Input Week value Property
- HTML DOM Input Number value Property
- HTML DOM Input Reset value property
- HTML DOM Input Search value property
