How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Get the Selected Radio Button Value in jQuery
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Get the Selected Radio Button Value in jQuery
Web Development

How to Get the Selected Radio Button Value in jQuery

how7o
By how7o
Last updated: May 22, 2026
3 Min Read
Get the selected radio button value with jQuery
SHARE

To get the selected radio button value with jQuery, combine the name attribute selector with the :checked pseudo-class: $('input[name="radio_button"]:checked').val(). Returns the value of whichever radio is currently selected, or undefined if none is.

Contents
  • The markup
  • The one-liner
  • React to selection changes
  • Default when nothing is selected
  • Vanilla equivalent
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 with jQuery 3.7. Originally published 2022-08-28, rewritten and updated 2026-05-17.

The markup

<input type="radio" name="radio_button" value="1" /> Yes
<input type="radio" name="radio_button" value="0" /> No

The one-liner

const value = $('input[name="radio_button"]:checked').val();
// "1" or "0", or undefined if nothing is selected

:checked matches the radio (or checkbox) that’s currently on; the bracket selector limits the match to the named group. .val() returns the value attribute as a string.

jQuery selected radio value — :checked selector, change handler, vanilla equivalent

React to selection changes

$('input[name="radio_button"]').on('change', function () {
    console.log('Selected:', this.value);
});

The change event fires on the newly-selected radio. Inside the handler, this is that radio element — read its value directly via this.value without re-querying the DOM.

Default when nothing is selected

// Falsy-default (treats empty string as "no selection" too)
const value = $('input[name="radio_button"]:checked').val() || '0';

// Strict-default (only kicks in when truly undefined)
const value = $('input[name="radio_button"]:checked').val() ?? '0';

Use ?? (nullish coalescing) when an empty string is a valid selection that you don’t want overridden. Use || when any falsy value should fall back to the default.

Vanilla equivalent

const selected = document.querySelector('input[name="radio_button"]:checked');
const value    = selected?.value;

?. short-circuits when nothing is selected, so value is undefined instead of throwing. Works on every modern browser without jQuery.

Frequently asked questions

What if no radio button is selected — what does .val() return?

undefined. The :checked selector returns an empty jQuery set when nothing matches, and calling .val() on an empty set returns undefined. Use a default with ? or ||: const v = $('input[name="x"]:checked').val() ?? '';.

How do I run code whenever the selection changes?

Attach a change handler to the radio inputs by name. The change event fires on the newly-selected radio: $('input[name="radio_button"]').on('change', function () { console.log(this.value); });. Inside the handler, this is the selected radio, so this.value reads its value directly.

Is the bracket selector [name="x"] case-sensitive?

Yes for the attribute value. HTML attribute names are case-insensitive (NAME and name match), but the value side is case-sensitive: [name="Radio_Button"] and [name="radio_button"] are different selectors. Keep your name= attributes consistent across HTML and JS.

What’s the vanilla-JS equivalent?

document.querySelector('input[name="radio_button"]:checked')?.value. The ?. safely short-circuits when nothing is selected. Works identically to the jQuery version in every modern browser, no library needed.

Related guides

  • How to Check if a Checkbox Is Checked with jQuery
  • How to Disable or Enable an Input with JavaScript or jQuery
  • How to Add a Required Attribute to Input Fields in jQuery

References

jQuery :checked selector: api.jquery.com/checked-selector. jQuery .val(): api.jquery.com/val. MDN :checked: developer.mozilla.org/en-US/docs/Web/CSS/:checked.

TAGGED:formsJavaScriptjQuery

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Get the last item from a PHP array How to Get the Last Item from an Array in PHP
Next Article Fix MySQL CONCAT returning NULL with COALESCE or CONCAT_WS How to Handle MySQL CONCAT Returning NULL
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

PHP add days to a date — strtotime and DateTimeImmutable side by side
Web Development

How to Add Days to a Date in PHP

5 Min Read
Get a favicon URL with JavaScript
Web Development

How to Get a Website’s Favicon URL with JavaScript

4 Min Read
Select all text in a contenteditable div on click
Web Development

How to Select All Text in a Contenteditable Div on Click

4 Min Read
WordPress prepare LIKE SQL — %s placeholder + % wildcards in the value
Web Development

How to Prepare a %LIKE% SQL Statement in WordPress

7 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?