2

I got the next html code and i want to get the array of checked radio buttons:

    <tr>
    <td>¿Cómo te llamas?</td>

    <td><input class="radio" type="radio" name="respuesta1" value="female"> Pablo</td>
    <td><input class="radio" type="radio" name="respuesta1" value="female"> Christian</td>
    <td><input class="radio" type="radio" name="respuesta1" value="female"> Alberto</td>


    </tr>

    <tr>
    <td>¿Cuánto es 2 + 2?</td>


    <td><input class="radio" type="radio" name="respuesta2" value="female"> 2</td>
    <td><input class="radio" type="radio" name="respuesta2" value="female"> 3</td>
    <td><input class="radio" type="radio" name="respuesta2" value="female"> 4</td>

    </tr>

As you can see, there arte two questions but i want only get the checked radios in a jquery array for the correct answers. Can you please help me?

2
  • you want the value of selected radio element? Commented Apr 6, 2014 at 20:52
  • Yes, that's what i want. Commented Apr 6, 2014 at 20:55

2 Answers 2

3

I think this might work

$(".radio:checked").each(function() {
console.log($(this).val());
});
Sign up to request clarification or add additional context in comments.

Comments

0

Try this then

    var selectedradio = "";
    var selected = $("input[type='radio'][name='respuesta1']:checked");
    if (selected.length > 0) {
        selectedradio = selected.val();

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.