Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/11/2004, 11:57
Avatar de JavierB
JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 23 años
Puntos: 772
Hola chemon

Prueba este código:
Código HTML:
<html>
<head>
<script>
function anadir(frm) { // añade un select al formulario
	elem=document.createElement('select');
  anadirOpt(elem,'Uno',1);
  anadirOpt(elem,'Dos',2);
  frm.appendChild(elem);
}
function anadirOpt(sel,txt,val) { //añade opciones a un select
	num=sel.options.length;
  selOpcion=new Option(txt,val);
  eval(sel.options[num]=selOpcion);
}
function borrar(frm) { //borra el último select añadido
	elem=frm.getElementsByTagName('select');
  sele=elem[elem.length-1];
  if(sele!='undefined') {
  	for(i in frm.childNodes)
    	if(frm.childNodes[i]==sele)
      frm.removeChild(frm.childNodes[i]);
  }
}
</script>
</head>
<body>
<form>
<input type="button" value="Añadir" onclick="anadir(this.form)" />
<input type="button" value="Borrar" onclick="borrar(this.form)" />
</form>
</body>
</html> 
Saludos,