How to get value of selected radio button using JavaScript ? Last Updated : 16 May, 2023 Comments Improve Suggest changes Like Article Like Report To get the value of the selected radio button, a user-defined function can be created that gets all the radio buttons with the name attribute and finds the radio button selected using the checked property. The checked property returns True if the radio button is selected and False otherwise. If there are multiple Radio buttons on a webpage, first, all the input tags are fetched and then the values of all the tags that have typed as 'radio' and are selected are displayed. Example 1: The following program displays the value of the selected radio button when the user clicks on Submit button. html <!DOCTYPE html> <html lang="en"> <head> <title> How to get value of selected radio button using JavaScript ? </title> </head> <body> <p> Select a radio button and click on Submit. </p> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female <input type="radio" name="gender" value="Others">Others <br> <button type="button" onclick="displayRadioValue()"> Submit </button> <br> <div id="result"></div> <script> function displayRadioValue() { var ele = document.getElementsByName('gender'); for (i = 0; i < ele.length; i++) { if (ele[i].checked) document.getElementById("result").innerHTML = "Gender: " + ele[i].value; } } </script> </body> </html> Output : How to get the value of the selected radio button using JavaScript? Example 2: The following program displays the values of all the selected radio buttons when submit is clicked. html <!DOCTYPE html> <html lang="en"> <head> <title> How to get value of selected radio button using JavaScript ? </title> </head> <body> <p> Select a radio button and click on Submit. </p> Gender: <input type="radio" name="Gender" value="Male">Male <input type="radio" name="Gender" value="Female">Female <input type="radio" name="Gender" value="Others">Others <br> Food Preference: <input type="radio" name="Food" value="Vegetarian">Vegetarian <input type="radio" name="Food" value="Non-Vegetarian">Non-Vegetarian <br> <button type="button" onclick="displayRadioValue()"> Submit </button> <br> <div id="result"></div> <script> function displayRadioValue() { document.getElementById("result").innerHTML = ""; var ele = document.getElementsByTagName('input'); for (i = 0; i < ele.length; i++) { if (ele[i].type = "radio") { if (ele[i].checked) document.getElementById("result").innerHTML += ele[i].name + " Value: " + ele[i].value + "<br>"; } } } </script> </body> </html> Output: How to get the value of the selected radio button using JavaScript? JavaScript is best known for web page development but is also used in various non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples. Comment More infoAdvertise with us Next Article How to get value of selected radio button using JavaScript ? B BhavyadeepPurswani Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to Get Selected Value in Dropdown List using JavaScript? A dropdown list is an HTML element that allows users to select one option from a list of options. The <select> and <option> tags are used to create dropdown lists in HTML. In this article, we will see how to get selected value from dropdown list using JavaScript.Basic HTML Structure for 2 min read How to get the value of radio button using AngularJS ? In this article, we will see how to get the value of the radio button using AngularJS, along with understanding the basic implementation through illustrations. The value of the checked radio button can be fetched with the help of the ng-model directive that helps to bind the data with the specific e 2 min read How to disable radio button using JavaScript ? Radio buttons let users select one option from many, commonly used in forms. Sometimes, based on a user's previous choice, certain options need to be disabled. For example, if a user selects "No" to playing games, we can disable related game options. Using JavaScript, about 65% of forms use such log 4 min read How to Disable Specific Readio Button Option using JavaScript? In this article, we will disable a specific radio button using JavaScript. Disabling specific radio button options using JavaScript involves targeting the specific option and then set its disabled property to true. This can be done by selecting the radio button option and modifying its disabled prop 2 min read How to calculate the sum of radio button values using jQuery ? In this article, we will see how to calculate the sum of radio button values using jQuery. To add the values of radio buttons, we will use the addition arithmetic operator. Approach: First, we will use radio buttons to select two numbers i.e. number1 and number2. If the user clicks on the radio butt 2 min read How to know which radio button is selected using jQuery? To check which radio button is selected in a form, we first get the desired input group with the type of input as an option and then the value of this selection can then be accessed by the val() method. This returns the name of the option that is currently selected. The selector 'input[name=option]: 2 min read How to check whether a radio button is selected with JavaScript ? Here are the different methods used to check the radio button is selected:1. Using Input Radio checked propertyThe checked property in JavaScript checks if a radio button is selected. By using document.getElementById or querySelector to get the radio button, the checked property returns true if the 3 min read How to unchecked a radio button using JavaScript/jQuery? In order to uncheck a radio button, there are a lot of methods available, but we are going to see the most preferred methods. In HTML, we can create radio buttons using the same name attribute, and by setting a unique value for each radio button within the group. Only one radio button within the gro 2 min read Get the Value of Text Input Field using JavaScript Getting the value of a text input field using JavaScript refers to accessing the current content entered by a user in an input element, such as <input> or <textarea>, by utilizing the value property. This allows for dynamic interaction and data manipulation in web forms.Syntax inputField 2 min read How to get the total number of radio buttons on a page using Selenium? When automating web testing with Selenium, one common task is to count the total number of radio buttons on a page. Radio buttons are crucial for selecting one option from a set of choices, and ensuring they are correctly displayed can be important for validating form functionality. In this guide, w 3 min read Like