Foros del Web » Programando para Internet » Javascript »

insertBefore no me funciona en IE, que anda mal?

Estas en el tema de insertBefore no me funciona en IE, que anda mal? en el foro de Javascript en Foros del Web. Hola Foro, Esto de Javascript me esta dando dolores de cabeza :P, con su ayuda he hecho una rutina para agregar celdas a una tabla ...
  #1 (permalink)  
Antiguo 03/12/2007, 15:18
 
Fecha de Ingreso: noviembre-2007
Mensajes: 35
Antigüedad: 16 años, 5 meses
Puntos: 0
insertBefore no me funciona en IE, que anda mal?

Hola Foro,

Esto de Javascript me esta dando dolores de cabeza :P, con su ayuda he hecho una rutina para agregar celdas a una tabla y funciona muy bien en Firefox, pero el problema viene cuando abro con el Internet Explorer, ya que marca un error, le active la herramienta para hacer debug y el error señala a la línea dónde esta el insertBefore.

Según yo todo el código esta normalito o habra por ahí algún parametro que no este bien puesto?

les dejo el código de la función JS
Código:
	var count=2;

	function addRows(id,mitabla,button){

		fila = mitabla.parentNode.parentNode;
		tbody = fila.parentNode;
		lineas = tbody.getElementsByTagName('tr');		
               
        var row = document.createElement('TR');
		row.className="background_ppm";

		var tn1 = document.createElement("TD"); 
		tn1.innerHTML="";
		tn1.setAttribute("colspan","8");
		    
		var tn2 = document.createElement("TD"); 
		if(button==1){
			tn2.innerHTML="<input type='button' onclick='removeRows(this)' value='&nbsp;-'>";
		}
		else{
			tn2.innerHTML="";
		}
		    
        var t0 = document.createElement("TD"); 
        celda0 =document.createElement("input");
        celda0.setAttribute("type","text");
        celda0.setAttribute("name","peso_charola_"+id+"[]");
        celda0.setAttribute("id","peso_charola_"+id);
        celda0.setAttribute("size","4");
        celda0.setAttribute("maxlength","8");
        celda0.setAttribute("style","text-align:right");
        celda0.setAttribute("onchange","calcula_ppm(" + id + "," + count + ")");
        celda0.setAttribute("align","center");
		t0.appendChild(celda0)
				
		var t1 = document.createElement("TD"); 
        celda1 =document.createElement("input");
        celda1.setAttribute("type","text");
        celda1.setAttribute("name","tot1_"+id+"[]");
        celda1.setAttribute("id","tot1_"+id);
        celda1.setAttribute("size","4");
        celda1.setAttribute("maxlength","8");
        celda1.setAttribute("style","text-align:right");
        celda1.setAttribute("onchange","calcula_ppm(" + id + "," + count + ")");
        celda1.setAttribute("align","center");
		t1.appendChild(celda1)
		
        var t2= document.createElement("TD"); 
        celda2 =document.createElement("input");
        celda2.setAttribute("type","text");
        celda2.setAttribute("name","tot2_"+id+"[]");
        celda2.setAttribute("id","tot2_"+id);
        celda2.setAttribute("size","4");
        celda2.setAttribute("maxlength","8");
        celda2.setAttribute("style","text-align:right");
        celda2.setAttribute("onchange","calcula_ppm(" + id + "," + count + ")");
        celda2.setAttribute("align","center");
		t2.appendChild(celda2)
		
        var t3= document.createElement("TD"); 
        celda3 =document.createElement("input");
        celda3.setAttribute("type","text");
        celda3.setAttribute("name","peso_pvc_"+id+"[]");
        celda3.setAttribute("id","peso_pvc_"+id);
        celda3.setAttribute("size","4");
        celda3.setAttribute("maxlength","8");
        celda3.setAttribute("style","text-align:right");
        celda3.setAttribute("onchange","calcula_ppm(" + id + "," + count + ")");
        celda3.setAttribute("align","center");
		t3.appendChild(celda3)
        

        var t4= document.createElement("TD"); 
        celda4 =document.createElement("input");
        celda4.setAttribute("type","text");
        celda4.setAttribute("name","ppm_"+id+"[]");
        celda4.setAttribute("id","ppm_"+id);
        celda4.setAttribute("size","4");
        celda4.setAttribute("readonly","");
        celda4.setAttribute("style","text-align:right; background-color:#9F9F9F");
        celda4.setAttribute("onchange","calcula_ppm(" + id + "," + count + ")");
        celda4.setAttribute("align","center");
		t4.appendChild(celda4)

		     
        
        
     	row.appendChild(tn1);  
        row.appendChild(t0);        
    	row.appendChild(t1);
   	    row.appendChild(t2);
        row.appendChild(t3);
        row.appendChild(t4);
		row.appendChild(tn2);

		for (i=0; ele = lineas[i]; i++){
		    if (ele==fila){
				break;
			}
		}    
		
		if (i==lineas.length-1){
			tbody.appendChild(row);
		}
		else{
			tbody.insertBefore(row,lineas[i+2]);	
		}

        count++;
   }
Qué anda?
  #2 (permalink)  
Antiguo 03/12/2007, 15:47
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Re: insertBefore no me funciona en IE, que anda mal?

Hola:

No sé que podrá ser... pueden ser muchas cosas, pero tal vez tengas un elemento con id="tbody"... o algún otro id que coincida con alguna variable... otra cosa podría ser que no esté bien referenciado... una buena costumbre sería controlar los tags...

fila = mitabla;
while (fila.tagName.toLowerCase() != "tr") fila = fila.parentNode;

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:42.