Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/03/2009, 08:29
NSNCxxxx
 
Fecha de Ingreso: agosto-2008
Mensajes: 30
Antigüedad: 16 años, 5 meses
Puntos: 0
Problemas con attachEvent y addEventListener

Hola como les va pero toy renagenado con agregar eventos dinamicamente, el problema esta en que al crear dinamicamente loc campos text cuando llamo al funcion AgregarEventos me sale que attachEvent y addEventListener esta indefinido .
Código:
function agregarEvento(elemento, nombre_evento, funcion, captura){    // para IE   
	if (elemento.attachEvent){alert("iE"+elemento.attachEvent); 
        elemento.attachEvent('on' + nombre_evento,function(){ funcion;} );   
        return true;   
    }else   // para navegadores respetan Estándares DOM(Firefox,safari)   
        if (elemento.addEventListener){alert("otro"+elemento.addEventListener);   
            elemento.addEventListener(nombre_evento,function(){funcion},captura);   
            return true;   
        }else  
		    {
			alert("otro"+elemento.addEventListener);	
			alert("iE"+elemento.attachEvent)
            return false;   
			}
}
ahora la creacion dinamica de texts
Código:
function agregarFilaGral(vec)
   {
	 tabla= document.getElementById(vec[0]);
	 // crea TR
	 row = document.createElement('tr');
	 //row.className=""+clase+"";
	 ID=contIDG;
	 vecG.push(ID);
	 row.id =""+vec[0]+ID+"";
	 for(i=1;i<vec.length;i++)
	    {
		 if(i==(vec.length-1))
		   {
		    ch=document.createElement('input'); 
            ch.type='checkbox'; 
	        ch.id=""+vec[i]+ID+"";
	        td1 = document.createElement("td");
		    td1.setAttribute("align","center");
		    td1.appendChild(ch);  
	        row.appendChild(td1); 
	       }
		else
		   {
		    texto = document.createElement('input');
	        texto.type='text';
	        texto.id=""+vec[i][0]+ID+"";
			for(j=1;j<vec[i].length;j++)
			 {
			  if(vec[i][j][0]=="width")
			   {
			    texto.style.width=vec[i][j][1];
			   }
			  else
			  {
			  //texto.setAttribute("on"+vec[i][j][0],vec[i][j][1]); 
			   agregarEvento(texto.id,vec[i][j][0],vec[i][j][1],false);
              }
			}
	 		//texto.setAttribute("onchange","verificar_carateresEsp(this.value)");   
		    td1 = document.createElement("td");
		    td1.setAttribute("align","center");   
			td1.appendChild(texto);
	        row.appendChild(td1); 
			alert(td1.innerHTML); 

	       }
		}
        	
	 tabla.appendChild(row);
	 contIDG++;
 }
la porcion de codigo en php
Código PHP:
echo "<div><table id='tablaE'>"
         echo 
"<tbody id='tablaRE'>";
         echo 
"<script>var v4=new Array('tablaRE',new Array('resp',new Array('change','verificar_carateresEsp(this.value)')),new Array('color',new Array('width','50px'),new Array('click','startColorPicker(this)'),new Array('keyup','maskedHex(this)')),'chRE');</script>";
        echo 
"<tr><td colspan='3'><div align='right'><img src='imagen/botones/fondodeA+.jpg' alt='agregar' onClick=\"agregarFilaGral(v4);\"/><img src='imagen/botones/elim.gif' alt='Eliminar Fila'  onClick=\"eliminarFilaGral('tablaRE','chRE');\"/><img src='imagen/botones/undo.gif' alt='Restaurar' onClick=\"restaurarFilaGral(v4);\" /></div></td></tr>";
      echo 
"<tr><td align='center'>Respuesta</td><td align='center'>color</td><td></td></tr>"