Get Radio Button value in Foreach- JS

1

I am trying to get the value of radio in JS using foreach

foreach($produtos as $produto){
 <input type="radio" id="<?php echo trim($produto->CODIGO); ?>" name="plano_ouro" value="<?php echo trim($produto->CODIGO); ?>">
}

no JS do not know how to get what I selected.

Thank you.

    
asked by anonymous 01.12.2014 / 12:16

2 answers

3

Here is the solution:

document.querySelector('input[name="plano_ouro"]:checked').value;
    
01.12.2014 / 12:20
1

@Antony's answer is correct. Here's the usage with jQuery:

$('input[name="plano_ouro"]:checked').val().
    
01.12.2014 / 17:39