How to send the value of a radio with the user id concatenated?

1

Good morning my doubts and complex is creating a system that will create card of each registered user, to differentiate the cards each element of the card has the id of the user. I would like to know how to capture the value of the selected radio, except that the name of the radio is concatenated with the id of the user to be able to differentiate itself from the other card.

Look at the codes:

THIS CREATES THE CARD

while ($registro = mysqli_fetch_array($resultado_id, MYSQLI_ASSOC)) {
    echo '<div class=" cardUser col-md-12">
    <div class="cardNome">
    <span>'.$registro['nome'].'</span>
    </div>
    <div class="cardPro">
    <span class="glyphicon glyphicon-education"> '.$registro['idProfissao'].'</span>
    <span class="cardPro2 glyphicon glyphicon-education"> '.$registro['idProfissao2'].'</span>
    </div>
    <div class="cardInfo">
    <ul class="cardUl">
    <li class="cardLi">
    <span class="cardValue glyphicon glyphicon-globe"> '.$registro['idCidade'].'</span>
    <span class="cardValue glyphicon glyphicon-earphone" id="tel"> '.$registro['telefone'].'</span>
    </li>
    </ul>
    <div class="estrelas">
    <ul class="cardUl">
    <li class="cardLi">
    <span class="cardLabel">Status:</span>
    <span class="cardValue"> '.$registro['disponibilidade'].'</span>
    </li>
    <li class="cardLi">
    <Form id="estrelas"> 
    <span class="cardLabel">Avaliação:</span>              
    <input type="radio" id="cm_star-empty-'.$registro['id'].'" name="fb'.$registro['id'].'" value="" checked/>
    <label for="cm_star-1-'.$registro['id'].'"><i class="fa"></i></label>
    <input type="radio" id="cm_star-1-'.$registro['id'].'" name="fb'.$registro['id'].'" value="1"/>
    <label for="cm_star-2-'.$registro['id'].'"><i class="fa"></i></label>
    <input type="radio" id="cm_star-2-'.$registro['id'].'" name="fb'.$registro['id'].'" value="2"/>
    <label for="cm_star-3-'.$registro['id'].'"><i class="fa"></i></label>
    <input type="radio" id="cm_star-3-'.$registro['id'].'" name="fb'.$registro['id'].'" value="3"/>
    <label for="cm_star-4-'.$registro['id'].'"><i class="fa"></i></label>
    <input type="radio" id="cm_star-4-'.$registro['id'].'" name="fb'.$registro['id'].'" value="4"/>
    <label for="cm_star-5-'.$registro['id'].'"><i class="fa"></i></label>
    <input type="radio" id="cm_star-5-'.$registro['id'].'" name="fb'.$registro['id'].'" value="5"/>
    </Form>
    </li>        
    <button type="button" class="btn btn-info btn-sm btn-like" id="btn-like-'.$registro['id'].'" data-id_usuario="'.$registro['id'].'">Avaliar</button>        
    </ul>
    </div>
    </div>
    </div>
    ';
}

This code and js that I use to send the variaves the id of the user I can capture more the value of the radio I do not know how to do.

<script type="text/javascript">
$(document).ready( function () {

    $('.btn-like').click(function(){
        var id_usuario = $(this).data('id_usuario');
        var estrela = $(this).data('');


        $('#btn-like-'+id_usuario).hide();

        $.ajax({
           url: 'like.php',
           method: 'post',
            data: { like_id_usuario: id_usuario,  },
            success:function (data) {
                alert('Registro realizado com sucesso');
            }
        });

   });
})
</script>
    
asked by anonymous 14.05.2018 / 11:54

1 answer

0

You can use slice to extract only part of the ID string after the size of the suffix you have. An example would be:

$('.btn-like').click(function() {
  var id_usuario = this.id.slice(9);

  $(this).hide();
  console.log('Utilizador: ' + id_usuario);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttonid="btn-like-1" class="btn-like">Utilizador 1</button>
<button id="btn-like-5" class="btn-like">Utilizador 5</button>
<button id="btn-like-15" class="btn-like">Utilizador 15</button>
    
14.05.2018 / 12:41