Question
Get the Selected Radio Button Value with jQuery
Question
I have two radio buttons in a form and want to submit the value of the option the user selects. Using jQuery, I can select all radio buttons with:
$("form :radio")
How can I identify which radio button is currently selected and retrieve its value?
Short Answer
You will learn how radio button groups work in HTML and how to use jQuery's :checked selector to find the selected option. You will also learn how to read its value safely, respond to selection changes, and avoid common selector mistakes.
Concept
Radio buttons represent a choice where the user may select one option from a group. HTML groups radio buttons by giving them the same name attribute.
<input type="radio" name="delivery" value="standard">
<input type="radio" name="delivery" value="express">
Because both inputs have name="delivery", selecting express automatically deselects standard.
In jQuery, :radio selects radio inputs, while :checked selects inputs that are currently checked. Combine them to find the selected radio button:
$('input[name="delivery"]:checked')
Call .val() on that jQuery selection to read the selected input's value attribute. This matters whenever a form needs to collect one user decision, such as a shipping method, payment type, account role, or survey answer.
Mental Model
Think of a radio group as a row of labeled switches connected by one wire. The shared name is the wire: only one switch on that wire can be on at a time.
:radiomeans “show me every switch of this type.”:checkedmeans “show me the switch that is currently on.”.val()means “read the label/value stored on that switch.”
The selector input[name="delivery"]:checked is like asking: “Among the delivery switches, which one is on right now?”
Syntax and Examples
Use :checked after a radio selector or after a specific name selector.
// All checked radio buttons on the page
$(':radio:checked')
// The checked radio button in one named group
$('input[name="delivery"]:checked')
// Its value
const deliveryMethod = $('input[name="delivery"]:checked').val();
Example:
<form id="order-form">
<label>
<input type="radio" name="delivery" value="standard" checked>
Standard delivery
</label>
<label>
<input type="radio" name="delivery" value="express">
Express delivery
</label>
Show choice
Step by Step Execution
Consider this HTML:
<input type="radio" name="plan" value="basic">
<input type="radio" name="plan" value="pro" checked>
And this jQuery code:
const $selectedPlan = $('input[name="plan"]:checked');
const planValue = $selectedPlan.val();
console.log(planValue);
Step by step:
input[name="plan"]finds both radio inputs because both belong to theplangroup.:checkedfilters that result to only checked inputs.- The
proradio button has thecheckedattribute initially, so$selectedPlancontains that one element. .val()reads its attribute.
Real World Use Cases
Radio button selection is useful when an app needs exactly one choice from a known set:
- Checkout forms: select
standard,express, orpickupdelivery. - Payment pages: choose
card,bank_transfer, orwallet. - User settings: choose a theme such as
light,dark, orsystem. - Survey forms: record one answer to a multiple-choice question.
- Admin dashboards: select one status or permission level.
For a normal HTML form submission, the browser already sends the selected radio button's name and value. jQuery is useful when you need the value immediately for validation, updating the page, or sending an AJAX request.
Real Codebase Usage
In real projects, make selectors specific to the form or component so unrelated radio groups cannot affect the result.
const $form = $('#checkout-form');
const delivery = $form.find('input[name="delivery"]:checked').val();
A common pattern is to update the interface when the user changes the selection:
$('input[name="delivery"]').on('change', function () {
const delivery = $('input[name="delivery"]:checked').val();
const message = delivery === 'express'
? 'Express delivery costs extra.'
: 'Standard delivery selected.';
$('#delivery-message').text(message);
});
Use validation before an AJAX request when a selection is optional in the HTML or created dynamically:
$('#checkout-form').on('submit', function (event) {
const $selected = $(this).find('input[name="delivery"]:checked');
($selected. === ) {
event.();
$().();
;
}
$().();
});
Common Mistakes
Using :radio without :checked
This selects every radio button, not the chosen one:
const value = $('form :radio').val();
.val() on several matched elements returns the value of the first matched element, which may not be selected.
Use:
const value = $('form :radio:checked').val();
Giving each radio button a different name
This allows multiple buttons to be selected because they are separate groups:
<!-- Incorrect for one choice -->
<input type="radio" name="standard" value="standard">
<input type="radio" name="express" value="express">
Comparisons
| Need | Recommended jQuery | Why |
|---|---|---|
| Find all radio buttons | $('form :radio') | Returns every radio input in the form. |
| Find selected radio buttons | $('form :radio:checked') | Filters to currently checked inputs. |
| Find the selected button in one group | $('input[name="delivery"]:checked') | Avoids matching other groups. |
| Get the selected value | $('input[name="delivery"]:checked').val() | Reads the selected input's value. |
| Test one known input | $('#express').prop('checked') | Returns true or false. |
Cheat Sheet
// Selected radio value in a named group
const value = $('input[name="groupName"]:checked').val();
// Selected radio element
const $selected = $('input[name="groupName"]:checked');
// Check whether the group has a selected input
const hasSelection = $('input[name="groupName"]:checked').length > 0;
// Listen for a changed choice
$('input[name="groupName"]').on('change', function () {
console.log($(this).val());
});
// Limit a search to one form
const valueInForm = $('#my-form')
.find('input[name="groupName"]:checked')
.val();
Rules:
- Radio buttons belong to the same group only when they share a
name. - Use
:checkedfor the current checked state. - Use
.val()to read thevalueattribute. - returns if the selector matches no element.
FAQ
How do I get the selected radio button value in jQuery?
Use a selector with :checked and call .val():
const value = $('input[name="delivery"]:checked').val();
Why does $('form :radio').val() return the wrong value?
That selector matches all radio buttons. Calling .val() on multiple elements reads the first matched element's value, not necessarily the checked one. Add :checked.
Can I use $('input:radio:checked')?
Yes. It works, although $('input[type="radio"]:checked') or $('input[name="delivery"]:checked') is often clearer and more specific.
What happens if no radio button is selected?
The selector matches nothing, so .val() returns undefined. Check .length or make a choice required.
Do radio buttons need the same name?
Yes, if they represent one choice. A shared name makes them a group and ensures only one can be selected.
Mini Project
Description
Build a small delivery-method selector for a checkout form. When the user chooses a radio option, show the selected method and its price. The project demonstrates selecting the checked radio button, reading custom data, and responding to the change event.
Goal
Display the currently selected delivery method and update its price whenever the user changes the radio selection.
Requirements
- Create three delivery radio buttons that share the
deliveryname. - Give each option a machine-readable
value. - Store a display price for each option.
- Show the initial selected method and price when the page loads.
- Update the displayed result when the user selects another option.
Keep learning
Related questions
Abort Ajax Requests with jQuery jqXHR.abort()
Learn how to cancel an in-progress jQuery Ajax request with jqXHR.abort(), handle abort status safely, and avoid stale UI updates.
Access the Correct this Inside a JavaScript Callback
Learn why JavaScript this changes in callbacks and how to preserve an object context using bind, arrow functions, and event handler patterns.
Add Key-Value Pairs to JavaScript Objects
Learn how to add key-value pairs to JavaScript objects with dot and bracket notation, dynamic keys, examples, and common mistakes.