Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the selected value of the radio button list in jquery?

I have radio button list which has id as the value, I want to access the selected id in the jquery function.

like image 298
Ravi Avatar asked Apr 13 '09 04:04

Ravi


People also ask

How do I get radio selected value?

Get the value of selected radio button: querySelector() Remember you need to specify the name property of the radio button in HTML code. It is used as document. querySelector('input[name="JTP"]:checked') inside the <script> tab to check the selected radio button value from the group of radio buttons.

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

Build A Paint Program With TKinter and Python The radiobutton has only two values, either True or False. If we want to get the output to check which option the user has selected, then we can use the get() method. It returns the object that is defined as the variable.

What is a radio button in HTML?

In HTML, a radio button is used to select one of many given choices. Radio buttons are shown in radio groups to show a set of related options, only one of which can be selected. A radio button in HTML can be defined using the <input> tag.

How do you check whether a Radiobutton is checked or not in Javascript?

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.


2 Answers

If you have HTML that looks like this:

<input type='radio' name='choices' value='1'> <input type='radio' name='choices' value='2'> <input type='radio' name='choices' value='3'> <input type='radio' name='choices' value='4'> <input type='radio' name='choices' value='5'> 

You would get the selected radio value with this:

$("input:radio[name='choices']:checked").val(); 
like image 194
Paolo Bergantino Avatar answered Sep 30 '22 03:09

Paolo Bergantino


It will get the selected value of the radiobutton at button click.
ex for list

$("#btn").click(function() {    $('input[type="radio"]:checked').val(); }); 
like image 20
Ashish Babu Avatar answered Sep 30 '22 01:09

Ashish Babu