Comunidad de diseño web y desarrollo en internet online

ayuda:Añadir y quitar inputs con appendchild

Citar            
MensajeEscrito el 04 Feb 2010 06:09 am
Hola..recurro al foro despues de mucho tiempo ya que hace tiempo que no programaba webs(menos con javascript :lol: )..en fin..mi problema es el siguiente: quiero aumentar inputs mediante TR's a una tabla con un unico boton y quitarlos cada uno con un boton (o link) individual. Adjunto codigo

Código Javascript :

i=0;
//AÑADIR CAMPO
function new_input(){
   
   fila = new Array();
   var campo1 = document.createElement("input");
   var campo2 = document.createElement("input");
   var campo3 = document.createElement("input");
   var drop = document.createElement("select");
   var sd1 = document.createElement("option");
   var sd2 = document.createElement("option");
   var sd3 = document.createElement("option");
   var sd4 = document.createElement("option");
   fila[i] = document.createElement("tr");
   var col1 = document.createElement('td');
   var col2 = document.createElement('td');
   var col3 = document.createElement('td');
   var col4 = document.createElement('td');
   var linc = document.createElement('a');
   linc.setAttribute("id","lnk");
   drop.setAttribute("name","unidad[]");
   sd1.setAttribute("value", "KG");
   sd2.setAttribute("value", "GR");
   sd3.setAttribute("value", "L");
   sd4.setAttribute("value", "ML");   
   campo1.setAttribute("name", "nnombre[]");
   campo2.setAttribute("name", "nprecio[]")
   campo3.setAttribute("name", "npres[]")
   campo1.setAttribute("maxlenght", "30");
   campo1.setAttribute("size", "12");
   campo2.setAttribute("maxlenght", "7");
   campo2.setAttribute("size", "7");
   campo3.setAttribute("maxlenght", "7");
   campo3.setAttribute("size", "7");
    document.getElementById("teibol").appendChild(fila[i]);
   fila[i].appendChild(col1);
   fila[i].appendChild(col2);
   fila[i].appendChild(col3);
   fila[i].appendChild(col4);
   drop.appendChild(sd1);
   drop.appendChild(sd2);
   drop.appendChild(sd3);
   drop.appendChild(sd4);
   sd1.appendChild(document.createTextNode("KG"));
   sd2.appendChild(document.createTextNode("GR"));
   sd3.appendChild(document.createTextNode("L"));
   sd4.appendChild(document.createTextNode("ML"));
   col1.appendChild(campo1);
   col2.appendChild(campo2);
   col3.appendChild(campo3);
   col3.appendChild(drop);
   col4.appendChild(linc);
   linc.setAttribute("href","javascript:remove("+i+")")
   linc.appendChild(document.createTextNode("Borrar"))
   i++;
   }
   //DELETEAR
   function remove(s){
      
      document.getElementById("teibol").removeChild(fila[s]);
}




Puedo crear correctamente...pero no borrarT_T lo que intento es borrar completamente el TR, pero solo borra el ultimo appendchild, espero puedan ayudarme, gracias de antemano.

Por izemaster

15 de clabLevel



Genero:Masculino  

chrome
Citar            
MensajeEscrito el 04 Feb 2010 06:42 pm
Problema solucionado..solo tenia q declarar el array fuera de la funcion :roll: ya que cada vez q la llamaba lo creaba de nuevo y con un solo elemento (el ultimo... :lol: ) De todas formas gracias ya que lo solucione con un addon del chrome que se encontraba en la pagina principal :lol:

Por izemaster

15 de clabLevel



Genero:Masculino  

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.