Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected radio buttons of certain class

I'm trying to get the radio buttons that has a certain class that is selected.

Getting the radio buttons of that class comes with

$("input:radio.someClass");

I thought that this would work to get the selected radio button -

$("input:radio.someClass:selected");

But that returns empty - what am I doing wrong?

like image 967
praks5432 Avatar asked Dec 03 '12 04:12

praks5432


People also ask

How can I check if a radio button is selected?

Using Input Radio checked property: The Input Radio checked property is used to return the checked status of an Input Radio Button. Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.

How do I get the radio button to be selected by default?

You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .

How can I check if a Radiobutton is selected in jQuery?

We can check the status of a radio button by using the :checked jQuery selector together with the jQuery function is . For example: $('#el').is(':checked') . It is exactly the same method we use to check when a checkbox is checked using jQuery.

How can I avoid multiple selected radio buttons?

To avoid having multiple radio buttons selected use the same name attribute. Radio buttons are normally presented in radio groups. Only one radio button in a group can be selected at the same time. The radio group must share the same name (the value of the name attribute) to be treated as a group.


2 Answers

Use this script

$("input:radio.classNmae:checked").val();
like image 81
M Tulaib Saleem Avatar answered Oct 07 '22 15:10

M Tulaib Saleem


According to JQuery documentation.

The :selected selector works for option elements. It does not work for checkboxes or radio inputs;

Try:

$("input:radio.someClass:checked");
like image 21
Akhil Sekharan Avatar answered Oct 07 '22 15:10

Akhil Sekharan