Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get value of selected radio button

The problem statement is simple. I need to see if user has selected a radio button from a radio group. Every radio button in the group share same id.

The problem is that I don't have control on how the form is generated. Here is the sample code of how a radio button control code looks like:

<input type="radio" name='s_2_1_6_0' value='Mail copy to my bill to address' id = "InvCopyRadio" onchange = 'SWESubmitForm(document.SWEForm2_0,s_4,"","1-DPWJJF")' style="height:20;width:25" tabindex=1997 > 

In addition to this when a radio button is selected it doesn't add a "checked" attribute to the control just text checked (I guess just the property checked without a value). Below is how a selected radio control looks like

<input type="radio" checked name='s_2_1_6_0' value='Mail copy to my bill to address' id = "InvCopyRadio" onchange = 'SWESubmitForm(document.SWEForm2_0,s_4,"","1-DPWJJF")' style="height:20;width:25" tabindex=1997 > 

Can anybody help me with jQuery code that can help me to get the value of checked radio button?

like image 598
user1114212 Avatar asked Dec 24 '11 02:12

user1114212


People also ask

How do 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 do you find the value of elements of a row of a table when the radio button is selected?

$("selector-for-the-table"). on("click", "input[type=radio]", function() { var row = $(this). closest("tr"); // ... }); If you want to get information from the other elements in that same row, you can use row.

Which method can be used to obtain the value associated with the selected radio button in Python?

Syntax: button = Radiobutton(master, text=”Name on Button”, variable = “shared variable”, value = “values of each button”, options = values, …) value = each radiobutton should have different value otherwise more than 1 radiobutton will get selected.


1 Answers

Just use.

$('input[name="name_of_your_radiobutton"]:checked').val(); 

It is that easy.

like image 183
Parveen Verma Avatar answered Sep 22 '22 17:09

Parveen Verma