This post will discuss how to check if any of the radio button is selected on submitting the form in JavaScript and jQuery.

1. Using jQuery

The basic idea is to use the :checked CSS pseudo-class selector which can represent any radio (<input type="radio">) that is checked. We can use this in many ways with jQuery:

1. Using is() function

We can use .is(selector), which matches against a selector expression. For example, suppose we have the following HTML code:

 
The following code uses .is() inside an event handler and returns true if any radio button is selected.


Edit in JSFiddle

2. Using val() function

The .val() method can be used to get the value of matched radio elements. When no options are selected, it returns an undefined value.


Edit in JSFiddle

3. Using length property

Alternatively, we can simply check the length property returned by the attributeEquals selector.


Edit in JSFiddle

2. Using JavaScript

In plain JavaScript, we can loop through each <radio> button using for…of loop:


Edit in JSFiddle

 
Or we can use the querySelector() method to access the matched element.


Edit in JSFiddle

That’s all about determining whether a radio button is selected in JavaScript and jQuery.