Ver Mensaje Individual
  #10 (permalink)  
Antiguo 26/06/2008, 14:58
Avatar de KarlanKas
KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 22 años, 4 meses
Puntos: 61
Respuesta: Como puedo agregar y eliminar opciones dentro de un SELECT de HTML con jav

Así te serviría? Con tu permiso lo he cambiado para que funcione tb en Firefox...

Dime si va

Código:
<html>
<head>
	<title>Div 04</title>
<script language= "javascript">
window.onload=function(){
	CreaLista();
	var pepe=document.getElementsByTagName("TD");
	for(a=0;a<pepe.length;a++){
		pepe[a].onclick=poblarLista
	}
}
	
function poblarLista(){
		id=this.id;
		t=this.innerHTML;
  		var cont=0;
  		existe = 'NO';
  		for(var i=0; i < oSelect.length; i++){
			if (id == combo[cont].value){existe = 'Si';}
	 		cont++;
		}
  		if (existe == 'NO'){
  			op = document.createElement("OPTION");
  			op.value = id; 
  			op.text = t;
  //op.selected = true;
  oSelect.options[cont] = op;
  document.body.appendChild(oSelect);

}
}

function CreaLista ()
{
  oSelect = document.createElement('SELECT');
  oSelect.id = "combo";
  oSelect.name = "Colores";
  op = document.createElement("OPTION");	
  op.value = '99';
  op.value = 'FFFFFF';
  op.text = 'Seleccione un color del cuadro';
  op.selected = true;
  oSelect .options[0] = op;
  document.body.appendChild(oSelect);
  oSelect.onchange=function() {ColorFondo(combo);};
}


function ColorFondo(c)
{
  document.bgColor = c.value;
}
</script>

</head>

<body >

<div id="div04" descrip = Color de fondo style="display: block">

<table border="3" id="Tabla">
<tr style="color:blue"><th colspan="5"></th>Tabla de colores</tr>
	<tr>
		<td name="celda1" id="FF0000" text="Rojo" style="background-color:red" >Rojo</td>
		<td id="0000FF" text="Azul" style="background-color:blue" >Azul</td>
	<tr>
		<td id="009900" text="Verde" style="background-color:green" >Verde</td>
		<td id="FFFF00" text="Amarillo" style="background-color:yellow" >Amarillo</td>
	</tr>
</table>

 
</div>

</body>
</html>
Un saludo!
__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.