Doubt to get the name of an input field automatically generated by php

1

I have a legacy php system that generates the input radios, and the names of these fields are dynamic, such as the $ row object. And now I need to get the values of the radios fields and their respective names so that they are saved in the bank through an ajax request. See the example:

<?php
   $row = new stdClass();
   $row->sigla = array('ag', 'bg', 'cg');
   foreach ($row->sigla as $r) {
       echo "<tr>
                <td style='text-align:center'><input type='radio' value='1' name='$r' class='avaliacao'>SIM</td>
                <td style='text-align:center'><input type='radio' value='2' name='$r' class='avaliacao'>NAO</td>
                <td style='text-align:center'><input type='radio' value='3' name='$r' class='avaliacao'>N/A</td>
            </tr><br/>";
          }
        ?>

And the js that are trying to execute, but not knowing how to get the name of the field:

$(document).ready(function(){
           $("input[type='radio']").click(function() {
                var value = $(this).val();//aqui retorna o valor correto
                //AQUI gostaria de pegar o valor do que foi clicado, mas como pegar o nome do campo?
            });
 });
    
asked by anonymous 23.10.2018 / 16:16

1 answer

2

So:

$(document).ready(function(){
    $("input[type='radio']").click(function() {
        var value = $(this).val();//aqui retorna o valor correto
        var nome = $(this).attr("name");
    });
});
    
23.10.2018 / 16:21