3
I wish my <button id="bottaaoPA">Comprar</button>
was only clickable if the radio
were marked.
Code:
$(function(){
var contador = 0;
$('.pa').click(function(){
if(contador === 0)
{
$(this).addClass("select");
$(this).hasClass("selectB");
$("#bottaaoPA").css("display","block");
$("#bottaaoPB").css("display","none");
$("#bottaaoPC").css("display","none");
contador = 1;
}
else
{
$(this).removeClass("select");
$("#bottaaoPA").css("display","none"); //apenas para teste
contador = 0;
}
});
});
$(function(){
$("#bottaaoPA").click(function(){
if($("input[name='bbt']").prop( "checked" ) &&
$("input[name='resp'").prop( "checked" ))
{
alert("Dois marcados");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="">
<h3><input type="radio" class="radio" id="radio1" name="bbt" value="bbt">Li e concordo com o <a href="#">Regulamento Geral BBT.</a></h3><br />
<h3><input type="radio" class="radio" id="radio2" name="resp" value="resp">Li e concordo com o <a href="#">Termo de Isenção de Responsabilidade</a> do evento.</h3>
<h5><img src="img/setaC-04.png"/><a href="#">Baixe aqui</a> a Ficha de Inscrição/Ficha Médica para a sua inscrição do evento.</h5>
</form>
<button id="bottaaoPA" disabled="disabled">Comprar</button>
Friend was not... still with 1 marked to push the button :/
– kaiquemix
Here works perfectly, press Run code snippet and you will see. for him to do nothing when only one radio is marked just delete the
else if
andelse
that he will only do something if they have both marked.– Leonardo
@Ivcs I took only left the IF but still it gets clickable
– kaiquemix
To leave clickable or not just using button friend, I put the way using button in the answer.
– Leonardo
Yes it is already so with disable but if I mark 1 it is already clickable :/
– kaiquemix
Bro you’re doing something wrong so look at the answer in the second
Executar trecho de código
will only activate the button if both are marked.– Leonardo
I completed the answer using the
div
, with the functionon
andoff
ofjquery
. Now with div also works, it will only be clickable if both checkbox are checked.– Leonardo
Opaaa, now it’s been discovered my mistake thank you :)
– kaiquemix