4
I have two inputs
of the kind radio
. Follow the code below:
<input type="radio" id="isgift0" name="isgift" value="0" class="arredondado" />
<label for="isgift0">Teste 1</label>
<input type="radio" id="isgift1" name="isgift" value="1" style="display: none;" />
<label for="isgift1">Teste 2</label>
And I have the following code on jQuery
:
$j('input[name=isgift]').click(function(){
if($j('#isgift1').is(':checked')){
$j(".gift-from").val(name_from);
$j(".gift-to").val(name_to);
$j(".mensagem-pedido").removeClass("divDisabled");
$j(".box-gift").addClass("divActive");
$j('#allow-gift-messages-for-order-container').show();
}
else if($j('#isgift0').is(':checked')){
$j(".gift-from").val('Anônimo');
$j(".gift-to").val(name_to);
$j(".box-gift").removeClass("divActive");
$j(".mensagem-pedido").addClass("divDisabled");
}
How they are ìnputs
of the kind radio
And with the same names, you can only mark one of the two. But I needed to do something else that I’m not getting. I wish when the first ìnput
,in the case with the id=isgift0
, if it was marked and the user clicked on it, it was unchecked. I wanted to do this only for this input.
His code is right, but what happens in this case is that he doesn’t even check the
input
and I wish that it could be checked and if the user clicked on it, it would be unchecked.– Matheus Portela
@Matheusportela I reviewed the question several times and realized that the need was different even. Edited, thanks for punctuating!
– Samuel Fontebasso
Samuel, I took a look and apparently the syntax is correct, but it hasn’t worked yet...
– Matheus Portela
@Matheusportela Missing put the
$j
.– Sam
@DVD Put the
$j
, but it still didn’t work...– Matheus Portela
What didn’t work? The stackoverflow snippet is doing something different than it should?
– Samuel Fontebasso
@Samuelfontebasso The stackoverflow snippet is working correctly, but by putting this in my code, it doesn’t work. The
input
is marked, but it does not clear.– Matheus Portela
@Matheusportela I don’t know why use jQuery with
$j
, maybe it’s eliminating the conflict with another library. However, I edited the answer with a direct example about the code you left in the question. If there’s another stretch that’s in conflict with this one there’s no way I know..– Samuel Fontebasso
@Samuelfontebasso I use jQuery with the
$j
, just as you said in your comment, to eliminate conflicts with other libraries. So, this example that you put up I had already done it, but it didn’t work either. And about the conflict, there’s nothing in my code that can do that, or that I use theseinputs
again.– Matheus Portela
Mark and uncheck one
input
with the code snippet you presented is ok. Go back, and start analyzing each step, use console.log at all to verify that each action is fired. Print text in the javascript console within the scope of the function fired with click to see if it is capturing the click oninputs
then a console.log inside the test if the input is marked aschecked
or not and, if there is some error in javascript before this snippet everything is stopped and does not run, see this too. There’s no secret if something doesn’t work you have to find where it’s stopping..– Samuel Fontebasso
@Samuelfontebasso I appreciate all your help and attention!
– Matheus Portela