Get Value From Radio Button In JavaScript | Code Snippet

9 Mar , 2013  Code Snippets 

Get-Values-From-Radio-Buttons-JSCode Snippet #6: Today’s code snippet teaches us how to get value from radio button in JavaScript. Using a simple JavaScript form validation, we will be fetching the values of the selected radio button using an alert window.

In one of our previous code snippet, we saw how to get values from multiple checkboxes if selected. Today, we will fetch the values from a radio button using a similar JavaScript used previously with the help of for loop again.

Demo: [Select a radio button and hit validate button]

The HTML Used:

The JavaScript Code Snippet for the validation:

As we saw in the checkbox JavaScript validation, we are using the same technique, but this time we are going to see if one a single radio button if checked, then get the value of that radio button using the code radioButtons[i].value and place it in the variable “param“. Once the for loop finishes, the value stored in param is displayed using the alert box.

Hope this code can help you in your upcoming projects. If you have any questions regarding the above code feel free to send us your queries by comments below. We are happy to clear your doubts and concerns in the code. If you have any other code for the same, please let us know the same.



, ,

Comments are closed.