1
I have a form where the user can register more than one passenger:
He can choose the type of passenger. See:
For each type of passenger, of course, a different value. Ex.:
- Adult: R$ 140,00
- Child up to 6 years: R$ 60,00
- Child from 6 to 12 years: R$ 90,00
- Adolescent from 12 to 18 years: 120,00
How do I, as it is selecting another field and according to the type of passenger, is calculated automatically in Total Value?
Check below the code I have:
<table border="0" width="100%">
<tr class='linhas'>
<td>
<table border="0" width="100%">
<tr>
<td style="padding: 5px">
<select id="TipoPassageiro" name="TipoDocumento[]" class="form-control">
<option>Pax</option>
<option value="Adulto">Adulto</option>
<option value="Adolescente entre 12 e 18 anos">Adolescente entre 12 e 18 anos</option>
<option value="Criança entre 6 e 12 anos">Criança entre 6 e 12 anos</option>
<option value="Criança de colo de até 6 anos">Criança de colo de até 6 anos</option>
</select>
</td>
<td style="padding: 5px"><input type="text" name="NomePAX[]" class="form-control" placeholder="Nome do pax" value=""></td>
<td style="padding: 5px">
<select id="TipoDocumento" name="TipoDocumento[]" class="form-control">
<option>Tipo de documento</option>
<option value="Carteira de Identidade">Carteira de Identidade</option>
<option value="Carteira Nacional de Habilitação">Carteira Nacional de Habilitação</option>
<option value="Carteira de Trabalho">Carteira de Trabalho</option>
<option value="Certidão de Nascimento">Certidão de Nascimento</option>
<option value="Passaporte">Passaporte</option>
<option value="Cédula de Identidade Estrangeira">Cédula de Identidade Estrangeira</option>
<option value="Outros">Outros</option>
</select>
</td>
<td style="padding: 5px">
<input type="text" name="Documento[]" class="form-control" placeholder="RG da pessoa autorizada" value="">
</td>
<td style="padding: 5px">
<input type="text" name="OrgaoEmissor[]" class="form-control" placeholder="Órgão Emissor" value="">
</td>
</tr>
</table>
</td>
<td style="padding: 5px" valign="top"><button type="button" class="removerCampo btn btn-danger" title="Remover linha"><i class="fa fa-minus-square" aria-hidden="true"></i> Remover</button></td>
<tr>
<td colspan="3"><button type="button" class="adicionarCampo btn btn-primary" title="Adicionar item"><i class="fa fa-plus-square" aria-hidden="true"></i> Adicionar mais passageiros</button></td>
</tr>
</table>
<div class="text-right">
<strong>Valor do Pacote:</strong> <span style="font-family: Arial"> R$ 150,00</span><br>
<strong>Valor Total:</strong> <span style="font-family: Arial"> R$ 0,00</span>
</div>
Jquery
<script type="text/javascript">
$(function () {
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
if ($('.linhas').length < 15) {
var adulto = '<?php echo $visualizar[1]->ValorAdulto; ?>';
var crianca6Anos = '<?php echo $visualizar[1]->ValorCrianca6Anos; ?>';
var crianca6a12Anos = '<?php echo $visualizar[1]->ValorCrianca6a12Anos; ?>';
var adolescentes = '<?php echo $visualizar[1]->ValorAdolescentes; ?>';
novoCampo = $("tr.linhas:first").clone();
novoCampo.find('input[type="text"]').val("");
novoCampo.find('select').val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
}
});
});
</script>
Where is the information of values (prices) in the code? And this
.prop('checked',true)
what do you mean? Looking at the code I didn’t see any checkbox or radiobutton.– Sam
I changed the code Sam. the values will come from BD through PHP.
– user24136
Field+field+field, why not calculate when the number appears?
– Risk
Right. Bring in 140.00 format.
– user24136
I don’t mean to be skeptical, Sam, but is it possible to do this automatic calculation? I ask because, as I am dealing with values related to different types of passengers, how will I be able to do so that, after the fifth field, when selecting Adolescents, identify how many fields selected as Adolescents were chosen earlier? I don’t know if my doubt is clear. I even took the solution that you passed in the previous post to try here, but it’s exactly at this point that I can’t move forward.
– user24136