He cambiado un poco tu estrategia, tenias un problema al intentar acceder secuencialmente a algo que podia no ser secuencial...
Analizalo si no lo entiendes pregunta, se trata de aprender no de que te lo den hecho.
Quim
Código HTML:
Ver original<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/JavaScript">
var num5=0;
var divs=new Array();
function crear5(obj) {
if(obj.checked) {
creaObjetos();
}else{
borrarTodos();
}
}
function borrarTodos(){
for (var i=0;i<divs.length;i++) {
fi5 = document.getElementById('fiel5');
fi5.removeChild(document.getElementById(divs[i]));
}
divs.splice(0,divs.length);
}
function borrar5(obj) {
for (var i=0;i<divs.length;i++){
if (divs[i]==obj){
fi5 = document.getElementById('fiel5');
fi5.removeChild(document.getElementById(obj));
break;
}
}
divs.splice(i,1);
if (divs.length==0) document.getElementById('estilo').checked=false;
}
function creaObjetos(){
if (divs.length <= 9) {
num5++;
fi5 = document.getElementById('fiel5');
contenedor5 = document.createElement('div');
contenedor5.id = 'div'+num5;
fi5.appendChild(contenedor5);
ele5 = document.createElement('select');
ele5.className = 'impCol';
ele5.length = 4;
variable = new Option("Ser","0");
ele5.options[0] = variable;
variable = new Option("Ser1","1");
ele5.options[1] = variable;
variable = new Option("Ser2","2");
ele5.options[2] = variable;
variable = new Option("ser3","3");
ele5.options[3] = variable;
contenedor5.appendChild(ele5);
ele5 = document.createElement('input');
ele5.type = 'button';
ele5.value = 'Añadir';
ele5.name = 'div'+num5;
ele5.className ='impCol';
ele5.onclick = function () {creaObjetos();}
contenedor5.appendChild(ele5);
ele5 = document.createElement('input');
ele5.type = 'button';
ele5.value = 'Borrar';
ele5.name = 'div'+num5;
ele5.className ='impCol';
ele5.onclick = function () {borrar5(this.name);}
contenedor5.appendChild(ele5);
ele5 = document.createElement('textarea');
ele5.className = 'impCol';
ele5.cols =100;
ele5.rows = 4;
ele5.maxlength =2000;
contenedor5.appendChild(ele5);
divs.push('div'+num5);
}else{
alert('maximo de 10 servidores');
}
}
<input name="estilo" id="estilo" onclick="crear5(this)" type="checkbox" value="" />