Problems with events in JS

Asked

Viewed 41 times

-2

I am doing an event in js, but the same is not working properly by the following fact if the user does not select at least one radio he does not trigger the event, as he would for the event to function as radio had in checked ??

<div class="radios-group">
<label>Forma de pagamento:</label><br>

                                  <?php if ($dados->atendimento_anotacoes <> null) {?>
                                    <div class="custom-control custom-radio">
                                        <input type="radio" id="dinheiro" name="forma-de-pagamento"
                                               class="custom-control-input" checked>
                                        <label class="custom-control-label" for="dinheiro">Dinheiro</label>
                                    </div>

                                   <?php }else{ ?>
                                    <div class="custom-control custom-radio">
                                        <input type="radio" id="cartao_debito" name="forma-de-pagamento"
                                               class="custom-control-input" checked>
                                        <label class="custom-control-label" for="cartao_debito">Cartão Débito</label>
                                    </div>
                                    <div class="custom-control custom-radio">
                                        <input type="radio" id="cartao_credito" name="forma-de-pagamento"
                                               class="custom-control-input">
                                        <label class="custom-control-label" for="cartao_credito">Cartão Crédito</label>
                                    </div>


                                  <?php } ?>

                                </div>

$(function () {

	        $('.radios-group').find('input:radio').click(function () {

        var url = this.id;



        $(this).closest('form').prop('action', 'process/' + url + '.php');

    });

});

  • 1

    If you explain better there’s no way to help, I don’t understand what you want to do.

1 answer

0

You have both radio buttons with the attribute checked tries to remove one of them.

<div class="custom-control custom-radio">
<input type="radio" id="dinheiro" name="forma-de-pagamento"
class="custom-control-input" checked>
<label class="custom-control-label" for="dinheiro">Dinheiro</label>
</div>


<div class="custom-control custom-radio">
<input type="radio" id="cartao_debito" name="forma-de-pagamento"nclass="custom-control-input">
<label class="custom-control-label" for="cartao_debito">Cartão Débito</label>
</div>

Browser other questions tagged

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