Hi everybody,
I'm trying to implement a dynamic select box using jQuery and I have some problems...
I have a 'route' to access to my DB and get the data of the new select box:
Route::get('contenidos/comboasign/{asignatura_id}', array('uses' => 'ContenidoController@comboAsignBloque'));
My Controller:
public function comboAsignBloque($asignatura_id)
{
if(Request::ajax()){
$bloque_id = Bloque::where('asignatura_id','=',$asignatura_id)->orderBy('nombre')->lists('id','nombre');
return json_encode(array("bloque_id" => $bloque_id));
}
}
And, in my View I have the form and the js:
$(document).ready(function(){
// Obtenemos los datos del selecbox1
$("#select_asignatura").change(function(e){
e.preventDefault();
var asignatura_id = $("#select_asignatura option:selected").val();
// AJAX request
$.get('comboasign/'+asignatura_id, function(data){
var select = $('#select_bloque');
select.empty();
// select.html(data);
});
});
});
I need something in my 'js' to show the data in my new 'selectbox_bloque'. With the 'select.html(data);' in the end, if I display that in a normal <div>, I can get something like this:
{"bloque_id":{"Bloque 1 de lengua":3,"Bloque 2 de lengua":4,"Bloque 3 de lengua":5}}
I need to put this array into my select box and I can't find out how...
I really appreciate any help.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community