Hi, I have a problem with my dynamic selector, it works correctly, except that it does not show me the values in the second select, I think the problem is in the java script code when printing the value in each select since I iterates correctly the number of semesters but does not show its value
Javascript code
$(function() {
$('#select-carrera').on('change', onselectcarrerachange);
});
function onselectcarrerachange() {
var pensum_id = $(this).val();
if (!pensum_id) {
$('#select-semestre').html('<option value "">Seleccione un semestre</option>') return
}
$.get('/api/nueva-seccion/' + pensum_id + '/semestres', function(data) {
var html_select = '<option value "">Seleccione un semestre</option>';
for (var i = 0; i < data.length; ++i) html_select += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
$('#select-semestre').html(html_select);
});
}
Html selectors
<div class="form-group col-sm-8">
<div class="input-group" title="Carrera">
<span class="input-group-addon"><i class="fa fa-graduation-cap" aria-hidden="true"></i>
</span>
<select class="form-control" id="select-carrera">
<option value="">Seleccione carrerra </option>
@foreach ($pensum as $n)
<option value="{{$n->id}} "> {{$n->carrera}} | Regimen: {{$n->regimen}} | Vigencia: {{$n->vigencia}} </option>
@endforeach
</select>
</div>
</div>
<div class="form-group col-sm-8">
<div class="input-group">
<span class="input-group-addon" title="Semestre" ><i class="fa fa-filter" aria-hidden="true"></i>
</span>
<select class="form-control" id="select-semestre">
<option value="">Semestres</option>
</select>
</div>
</div>
Capture my console with a console.log (data);
[! [enter the description of the image here] [2]] [2]
Console.log before the for
console.log(data);
var html_select='<option value "">Seleccione un semestre</option>';
for ( var i =0 ; i<data.length; ++i)
html_select +='<option value="'+data[i].id+'">'+data[i].name+'</option>';
$('#select-semestre').html(html_select);
});