I have the following code js that does the following:
Shows in an orderly fashion what it recovers from an array in a select but I do not know how to make print on it if the selected product is solid or liquid .. I have blocked, and therefore I use your help. I leave only the JS code.
It is worth mentioning that you already try to place document.getElementById("tipo").innerHTML = tipo;
after document.getElementById("lista").innerHTML = document.write(text);
but it does not work.
producto = [
/*
a: Abreviacion Formula
n: Nombre con espacio igual espacio ( = )
v: valor inicial
t: tipo de producto true para liq y false para sol
*/
{ c: " ", n: 'Jabon en Pasta', v: 0, t: "sol" },
{ c: " ", n: 'Ambientador', v: 0, t: "liq" },
{ c: " ", n: 'Cloro', v: 0, t: "liq" }
];
producto.sort(function(a, b) {
if (a.n > b.n) {
return 1;
}
if (a.n < b.n) {
return -1;
}
// a must be equal to b
return 0;
});
function selector() {
// document.getElementsByTagName("option").addEventListener("click", location.reload());
var selec = document.getElementById("mySelect").value;
document.getElementById("formula").innerHTML = selec;
document.getElementById("mySelect").value = "";
document.getElementById("entrada").value = "";
document.getElementById("salida").innerHTML = "";
document.getElementById("procedimiento").innerHTML = "";
}
function salidaproducto() {
text = "<select class='form-control' id='mySelect' onchange='selector();'>";
for (li in producto) {
var tipo = "";
if (producto[li].t == "liq") { tipo = "Liquido"; } else { tipo = "Solido"; };
text += "<option>" + producto[li].n + "</option>";
}
text += "<option value='' disabled selected hidden>Seleccione un Producto...</option>";
text += "</select>";
document.getElementById("lista").innerHTML = document.write(text);
}