Ver Mensaje Individual
  #5 (permalink)  
Antiguo 21/06/2008, 12:48
MatiasDV
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: onclick en el body, que valores obtengo?

porque no entiendo que haces en algunos lugares, me comentas que condiciona pero que hace esto: evt = evt || event; (que hacen las barras verticales?, es un "if" sobre "evt" si es falso?)

"evt.target" que es target? (soy novato, conozco .value [Valor] .text [texto] .id [identificador] .name [nombre])

"evt.srcElement" que srcElement?

----------------------

Bueno, pese a estas dudas, con las aclaraciones que me hiciste pude ralizar lo que queria, gracias y aqui mi codigo con el onclick en el BODY, mi problema era que usaba this y en este caso el valor asignado era cualqueira (mas bien vacio), tenia que usar event. Aun que sigo sin entender que es srcElement.

GRACIAS!!!!

Código:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Div 04</title>
</head>

<body onload="CreaLista();" onclick="PoblarLista (event.srcElement);" >

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

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



<script language= "javascript">

//document.getElementById('Tabla').onclick = PoblarLista;
//document.onclick = function(evt){ evt = evt || event; PoblarLista(evt);};

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.attachEvent('onchange', function() {ColorFondo(combo);});
}

function PoblarLista (id)
{ 
  if (id.nodeName == 'TD')
  {
  	  alert ("value: " + id.value);
  	  alert ("text: " + id.text);
//	  alert ( "color: " + id.color);
	  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.value; 
	  op.text = id.text;
	  //op.selected = true;
	  oSelect.options[cont] = op;
	  document.body.appendChild(oSelect);
  	}
  }
}

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

</body>
</html>