Answer the question
In order to leave comments, you need to log in
How to connect a checkbox and a button so that others are not pressed?
I have blocks that are formed from the base in a cycle, and in general it is necessary that there be a check box when clicking on which the button is activated or deactivated. But due to the fact that I have, let's say, 2 elements came from the cycle, then the checkbox activates all the buttons. How to make a button and a checkbox linked within the same element?
Answer the question
In order to leave comments, you need to log in
$('селектор чекбокса').on('change', function() {
$(this)
.closest('селектор блока с чекбоксом и кнопкой')
.find('селектор кнопки')
.prop('disabled', !this.checked);
}).change();
<div id='block-check-button' class="custom-control payment-checkbox mb-4 pl-2">
<input type="checkbox" id="checkPay" class="custom-control-input">
<label class="custom-control-label labelSms" for="customCheck1">Согласен с расчетом суммы к оплате</label>
</div>
<form action="" method="post">
<div class="button_submit_payment">
<button type="submit" id='payButton' class="buttonPayment btn-sm disablePayButton" id="paymentButton" disabled=""><?=GetMessage('PAYMENT')?></button>
</div>
$('#checkPay').on('change', function() {
$(this)
.closest('#block-check-button')
.find('#payButton')
.prop('disabled', !this.checked);
}).change();
input:not(:checked) + button {
pointer-events: none;
opacity: 0.5;
}
// либо
// input:not(:checked) + div button
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question