jQuery

jQuery Selected Radio Button Value Examples (1 line code)

Have you ever wondered how to use jQuery to  get selected radio value? In this article, I am going to show you two easy and simple ways to do that. Each method has only 1 line of code, so it’s super duper easy to follow along and implement it.

How to Get Selected Radio Button Value using jQuery – Examples

Let’s say that you have a form with ID: “form1” and “country” is the ID radio button for which you are trying to find out the selected value. Now here are the 2 ways in which you can use do it:

Example 1: Using :checked

$('#form1 input[name=country]:checked');

Example 2: Using .val()

$('input[name=country]:checked', '#form1').val();
That’s it!

Do you know of any other ways to use jQuery to get selected radio button value? Feel free to share by commenting below.

2 Comments on jQuery Selected Radio Button Value Examples (1 line code)

  1. 1

    Very nice and usefule information. Is there any common code to extract values from both textbox and radiobutton?

    • 2

      Hi Kumar,
      Yes, there is. In fact, it’s even simpler for a textbox. In the examples shown in this article, let’s assume that we have a textbox for First Name of the user with ID “first_name”. So the code for getting the value of this textbox by it’s name would be:
      $('input[name=first_name]').val();

      Get the textbox value by using it’s ID:
      $('#first_name').val();

      Hope that helps.

Leave a Reply to Robert Cancel reply

*

*