En el ejemplo siguiente se borran todos los OPTION de un select ("sel") uno por uno y a continuación se añaden los OPTION deseados:
var sel = document.getElementById("idSelect");
for(i=(sel.length-1); i>=0; i--)
{
aBorrar = sel.options[w];
aBorrar.parentNode.removeChild(aBorrar);
}
for(i=0; i<cantidadOptions; i++)
{
option = document.createElement("OPTION");
option.value = "valor";
option.text = "texto";
sel.add(option);
}
W-->i for iteration?
ResponderEliminaris not W
Eliminaris 0
Este comentario ha sido eliminado por el autor.
ResponderEliminarvar sel = document.getElementById("idSelect");
ResponderEliminarfor(i=(sel.length-1); i>=0; i--)
{
aBorrar = sel.options[w];
aBorrar.parentNode.removeChild(aBorrar);
}
Es igual a ...
document.getElementById("idSelect").innerHTML="";