Get values โ€‹โ€‹of all checked radio buttons using JQuery

Using JQuery I am trying to perform validation and also get the values โ€‹โ€‹of all dynamically generated radio buttons on the page.

I have 10 questions on my page and each question has a radiobook group (YES / NO).

when you click on the radio button i want to submit it to the database for the question, this is my code

<p>Question 1</p>
<input id="1_1" type="radio" name="1" value="Yes" />
<input id="1_2" type="radio" name="1" value="NO" />

      

I searched on google and found this code

$('input[name=radioName]:checked', '#myForm').val()

      

But I don't know how to use it correctly?

+3


source to share


2 answers


According to your HTML structure, try this: -



var arr = []; // take an array to store values
$('input[type="radio"][name="1"]:checked').each(function(){
   arr.push($(this).val());  //push values in array
});

      

+2


source


If you want the values โ€‹โ€‹of everyone <radio>

, you can do



var ans = $('[name=1]:checked').map(funciton(){
    return $(this).val();
}).get();

      

0


source







All Articles