Ver Mensaje Individual
  #8 (permalink)  
Antiguo 07/01/2013, 20:32
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 17 años, 8 meses
Puntos: 1567
Respuesta: evento onfocus

Cita:
Iniciado por Panino5001 Ver Mensaje
En lugar de elValor es mejor usar
Código:
document.getElementById(elemento).defaultValue;
Muy buena como siempre @Panino5001, nunca la había usado

Entonces nos quedaría
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. function fnc(elemento){
  9. var valor = document.getElementById(elemento);
  10. if(valor.value == valor.defaultValue){
  11. valor.value = "";
  12. }
  13. }
  14.  
  15. //]]>
  16. </head>
  17. <form action="#">
  18. <input type="text" value="hola" id="nombre" onfocus="fnc(this.id)" /><br />
  19. <input type="text" value="hola2" id="nombre2" onfocus="fnc(this.id)" /><br />
  20. </form>
  21. </body>
  22. </html>

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.