miércoles, 6 de enero de 2010

Saber que objeto tiene el cursor

<script type="text/javascript">
var activeElement;
function blurFunc(){
activeElement = null; /* Cuando el elemento deja de estar activo el elemento activo pasa a ser nulo (null) */
}

function focusFunc(evento){
if(!evento){ // Para IE
evento = window.event;
activeElement = evento.srcElement; /* Cuando un elemento se activa (focus) lo indicamos */
}
else{ // Para otros navegadores
activeElement = evento.target;
}
alert(activeElement.name); // Lo utilizaremos para hacer la prueba
}

function init() {
for (var i = 0; i < document.forms.length; i++) {
for(var j = 0; j < document.forms[i].elements.length; j++) {
document.forms[i].elements[j].onfocus = focusFunc;
document.forms[i].elements[j].onblur = blurFunc;
}
}
}

window.onload = init;
</script>

<body>
<form name="WebTaller" action="">
Nombre: <input type="text" name="nombre">
Apellidos: <input type="text" name="apellidos">
</form>
</body>

No hay comentarios:

Publicar un comentario