1
I have the following problem, I have in my form several questions that are treated using the radio button, as print attached. I am using jquery to change the color of the button when it is selected, the problem is that when the person selects the type of the request and goes in the bottom row to select the service deadline, the top row she had selected loses the selection, And you wouldn’t want that to happen, how do you fix that? A javascrip solution would also suit me.
HTML
<div class="row form-group">
<div class="col-md-8">
<div class="btn" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="motSolic" id="motNovaFuncao" value=3 autocomplete=off> Nova Função
</label>
<label class="btn btn-info">
<input type="radio" name="motSolic" id="motRemanejamento" value=4 autocomplete=off> Remanejamento
</label>
<label class="btn btn-info">
<input type="radio" name="motSolic" id="motAumentoQuadro" value=5 autocomplete=off> Aumento de Quadro
</label>
<label class="btn btn-info">
<input type="radio" name="motSolic" id="motSubstituicao" value=6 autocomplete=off> Substituição de Colaborador
</label>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-md-4">
<label>Prazo do Serviço:</label>
</div>
</div>
<div class="row form-group">
<div class="col-md-4">
<div class="btn" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="prazoServico" id="motTemporario" value=7 autocomplete=off> Temporário
</label>
<label class="btn btn-info">
<input type="radio" name="prazoServico" id="motIndeterminado" value=8 autocomplete=off> Indeterminado
</label>
</div>
</div>
</div>
JQUERY
<script>
$(document).ready(function(){
$('#identAbertura').change(function(){
$('.btn').removeClass().addClass('btn').addClass('btn-default');
$(this).parent().removeClass("btn-default").addClass("btn-success");
});
$('#identMov').change(function(){
$('.btn').removeClass().addClass('btn').addClass('btn-default');
$(this).parent().removeClass("btn-default").addClass("btn-success");
});
});
</script>
The name="" of your input radio understands that it is part of the same input group when set to the same value, in your case all inputs have name="motSolic", if each receive a different name, this will not happen when you click on another, because your code will understand that it is not part of the same input group with name="" different, but if you want to keep two input radio options, you should keep two equal values for name=""but in doing so, the selected gets focus and the losing focus will also lose its default css sheet style.
– ElvisP
Eliseu, I edited the html code of my question, if you notice, the name=", are different, this I had modified and still have problems.
– Marcilio Eloi