I would like you to help me with this question and how to solve it. I have 2 div, the second div is hidden depending on what I select in the first div, until then everything is fine, because I can hide or show the div.
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for=""> Tiene Seguro</label>
<select name="seguro" id="seguro">
<option value="1" @if($user->seguro==1) selected @endif>SI</option>
<option value="2" @if($user->seguro==2) selected @endif>NO</option>
</select>
</div>
</div>
</div>
<div class="row" id="tipoSeguro" style="display:none">
<div class="col-sm-12">
<div class="form-group">
<div class="form-check">
<label class="form-check-label"><input class="form-check-input" name="tipo" type="radio" value="1" @if($user->tipo_seguro==1) checked @endif>Médico - Dental</label>
</div>
<div class="form-check">
<label class="form-check-label"><input class="form-check-input" name="tipo" type="radio" value="2" @if($user->tipo_seguro==2) checked @endif>Otros</label>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function (){
$('#seguro').append(function (){
if($(this).val()==1){
$('#tipoSeguro').show();
}else if($(this).val()==2){
$('#tipoSeguro').hide();
}else if($(this).val()==""){
$('#tipoSeguro').hide();
}
});
});
</script>
My problem comes when I want to edit the form and the div that must be shown is shown or hidden, but if I change the option of the secure selection by YES, the hidden div should be displayed, before I had it with a click (function () ), but I did not do anything if the secure select was YES, it was not shown, I changed it to the append, but now it does not change if you selected Yes or NO.
Help, thanks