![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
17/02/2004, 19:24
|
![Avatar de KarlanKas](http://static.forosdelweb.com/customavatars/avatar11549_2.gif) | Moderador extraterrestre | | Fecha de Ingreso: diciembre-2001 Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 23 años, 1 mes Puntos: 61 | |
Un pequeño truco podría ser que tuvieras en el formulario un campo oculto que contuviera el nombre del campo que tiene el foco. De esta forma sólo tendrías que recurrir a él cuando quisieras saber quién tiene el foco.
Luego si quieres hacer algo en el campo que tenga el foco sólo tendrías que usar el eval así:
formulario=document.forms[0];
tieneElFoco=eval("document.forms[0]."+formulario.foco.value);
y ya si quisieras, por ejemplo cambiar el valor de dicho campo sólo tendrías que poner:
tieneElFoco.value="pepito";
Te he puesto un pequeño ejemplo con el campo del foco no oculto para que veas como cambia. Espero que te ayude!
<html>
<head>
<title>Untitled</title>
<style>
*{font=normal 10px/10px verdana;
color:black;}
input{position:absolute;
left:100px;}
</style>
</head>
<body>
<form>
Tiene el foco: <input
type="input"
readonly=readonly
name="foco" />
<br />
<br />
Pepe: <input
onfocus="this.form.foco.value=this.name;"
type="text"
name="pepe" />
<br />
<br />
Pepe1: <input
onfocus="this.form.foco.value=this.name;"
type="text"
name="pepe1" />
<br />
<br />
Pepe2: <input
onfocus="this.form.foco.value=this.name;"
type="text"
name="pepe2" />
<br />
<br />
Pepe3: <input
onfocus="this.form.foco.value=this.name;"
type="text"
name="pepe3" />
</form>
</body>
</html>
__________________ Cómo escribir
No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia. |