0
I wish that when it was selected "brother" in the radio
the value of checkboxes
fold.
function soma_valores(campo) {
if (campo.checked) {
var valor_anterior = parseFloat(document.getElementById("Preco").value);
var valor_novo = valor_anterior + parseFloat(campo.value);
document.getElementById("Preco").value = valor_novo;
} else {
var valor_anterior = document.getElementById("Preco").value;
var valor_novo = valor_anterior - campo.value;
document.getElementById("Preco").value = valor_novo;
}
}
$(function() {
var documentType = $('#documentType2');
documentType.hide();
function showInput(id) {
if (id == 'irmao' || id == 'Dois_Cursos') {
$('#documentType2 label').text('90.00');
$('#documentType2 input').prop('Preco');
$('#Preco').val('90.00');
documentType.show();
}
if (id == 'Bolsista') {
$('#documentType2 label').text('R$ 00.00');
$('#documentType2 input').prop('Preco');
$('#Matricula').val('30.00');
$('#Preco').val('00.00');
documentType.show();
}
if (id == 'Nenhum') {
$('#documentType2 label').text('60.00');
$('#documentType2 input').prop('Preco');
$('#Matricula').val('30.00');
$('#Preco').val('60.00');
documentType.show();
}
}
$(document).on('click', 'input[type=radio]', function() {
var id = $(this).prop('id');
showInput(id);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="campo">
<div class="exemplo-radio">
<fieldset>
<legend>Selecione o tipo de pacote
<font color="red">*</font>
</legend>
<label><input type="radio" name="Tipo_Desconto" id="irmao" value="Irmão" required> Irmão</label>
<label><input type="radio" name="Tipo_Desconto" id="Bolsista" value="Bolsista" required> Bolsista</label>
<label><input type="radio" name="Tipo_Desconto" id="Dois_Cursos" value="Dois cursos" required>2 cursos</label>
<label><input type="radio" name="Tipo_Desconto" id="Nenhum" value="Nenhum" required>1 curso</label>
</fieldset>
</div>
</div>
<div class="campo">
<fieldset>
<legend>Adicional</legend>
<label class="container">Matrícula<input class='shared' type='checkbox' value='30.00' id='Matricula' name='Matricula' onclick='soma_valores(this)'/><span class="checkmark"></span></label>
<label class="container">Figurino<input class='shared' type='checkbox' value='50.00' id='Figurino' name='Figurino' onclick='soma_valores(this)'/><span class="checkmark"></span></label>
</fieldset>
</div>
<div id="documentType2">
<legend>Valor</legend>
<input type='text' autocomplete='off' value='0.00' id='Preco' name='Preco' readonly pattern='^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÊÍÏÓÒÖÚÇÑ ]+$' maxlength='500' />
I haven’t looked at everything, but
id == 'irmao' || 'Dois_Cursos'
is wrong. It should beid == 'irmao' || id == 'Dois_Cursos'
. You can improve that great amount ofifs
using theswitch/case
.– Woss
I appreciate the tip, although it has nothing to do with my doubt.
– Raul Meira
The first part yes, as it is wrong can interfere with the result.
– Woss