0
Today I use this function to disappear the div, works perfectly, But I need the field already selected /option value="boletos" Selected/Boletos/option/ but the function is only executed when it changes because this defined onchange, Is there an Event load that when opening the screen identifies what is selected in the option and execute the function? onload, onpageshow, etc. does not work
Summarizing when the screen opens it identifies that the field select "Boletos" is selected and hides the others.
THANK YOU!!
function ocultar_div(){
$('.div-sel').hide();
$('#TipodeDocumento_6').on('change', function() {
var selecionado = $(this).val();
$('.div-sel').each(function() {
if ($(this).attr('id') == selecionado) {
$(this).toggle();
} else {
$(this).hide();
}
});
});
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="col-md-3" >
<div class="form-group">
<label for="TipodeDocumento_6" >Tipo de Documento</label>
<select class="form-control" name="TipodeDocumento_6" id="TipodeDocumento_6">
<option value="">Selecione</option>
<option value="Contratos_Aditivos">Contratos e Aditivos</option>
<option value="Notas_Fiscais">Notas Fiscais</option>
<option value="boletos" selected>Boletos</option>
</select>
</div>
</div>
<div class="div-sel panel panel-default" id="boletos">
<div class="panel-heading ">
<h3 class="panel-title"> <b>Boletos</b> </h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="ServioProduto_4">Serviço/Produto</label>
<input type="text" class="form-control" name="ServioProduto_4" id="ServioProduto_4">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="RazaoSocial_Boletos">Razão Social</label>
<input type="text" class="form-control" name="RazaoSocial_Boletos" id="RazaoSocial_Boletos">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="CNPJFornecedor_Boletos">CNPJ do Fornecedor</label>
<input type="text" class="form-control" name="CNPJdoFornecedor_10" id="CNPJdoFornecedor_10">
</div>
</div>
</div>
</div>
</div>
I put in the <body onload="Function()" - as it indicated and worked. even updating the selected option is generated. !
– Rapha