jQuery does not capture custom radiobutton clicked (click)

Asked

Viewed 35 times

1

I have a simple HTML that

<input name="chave_binaria" type="radio" id="radio_39" value="1" class="with-gap radio-col-green" checked>
<label for="radio_39">Esquerda</label>

<input name="chave_binaria" type="radio" id="radio_40" value="2" class="with-gap radio-col-green">
<label for="radio_40">Direita</label>

And I have the following jQuery code:

$(document).ready(function(){

    $(document).on('change', 'input[name="chave_binaria"]', function(){

        let binary_key = $('input[name="chave_binaria"]:checked').val();

        $.ajax({
            url: baseURL+'requests/change_binary_key',
            data: {key: binary_key},
            type: 'POST',
            dataType: 'json',

            success: function(callback){

                if(callback.status == 1){

                    new Noty({
                        type: 'success',
                        text: '<i class="fa fa-check"></i> Chave binária alterada com sucesso!',
                        timeout: 3000
                    }).show();

                }else{

                    new Noty({
                        type: 'error',
                        text: '<i class="fa fa-times"></i> Erro ao alterar chave binária. Tente novamente.',
                        timeout: 3000
                    }).show();
                }
            },

            error: function(message){
                console.log('Erro ao alterar chave binária: ', message.responseText);
            }
        });

    });

}); /* ready */

When I click on radio button to check it, the jQuery function I created does not perform. I have tried using jQuery click in the function and also nothing. If I leave the radio button of the "raw" form of the HTML it works normally. What can be?

  • I gave Ctrl+C > Ctrl+V in your code and is capturing the click on radio perfectly. Only thing I changed was changing the function ajax by a console.log('Click capturado');. There is an error in your project console when you run the complete code?

  • This is because your radio is customized, you have to use the inspector Object to see where you are clicking.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.