Estoy intentando añadir opciones a un select
, pero lo que ocurre es que se añaden pero vacías: <option></option>
. Les muestro mi código:
//AQUÍ MIRO EL VALOR DE UN SELECT ANTERIOR, PORQUE DE ESTE DEPENDE EL RESTO
var typeID = document.getElementById("type");
var type = typeID.options[typeID.selectedIndex].value;
//AQUÍ PONGO LOS VALORES DEL SELECT PARA AMBOS CASOS
item0={
o1:{value:1,text:"Texto 1"},
o1:{value:1,text:"Texto 2"},
o2:{value:2,text:"Texto 3"}
}
item1={
o1:{value:1,text:"Texto 1"},
o2:{value:2,text:"Texto 2"}
}
//SI EL VALOR DE "TYPE" ES 0, SE AÑADEN UNOS SELECT, SI ES 0, OTROS.
if (type == 0) {
$.each(item0, function (i, item) {
$('#action').append($('<option>', {
value: item0.value,
text : item0.text
}));
});
} else if (type == 1) {
$.each(item1, function (i, item) {
$('#action').append($('<option>', {
value: item1.value,
text : item1.text
}));
});
}