Foros del Web » Programando para Internet » Javascript »

Ayuda a dar el foco

Estas en el tema de Ayuda a dar el foco en el foro de Javascript en Foros del Web. hola, tengo una funcion ( y si hay una mejor, agradeceria que me la pasasen xD) que quiero que si el usuario no entro un ...
  #1 (permalink)  
Antiguo 10/02/2010, 16:49
Avatar de rudy69  
Fecha de Ingreso: octubre-2008
Ubicación: espndeportes.com
Mensajes: 195
Antigüedad: 15 años, 6 meses
Puntos: 7
Ayuda a dar el foco

hola, tengo una funcion ( y si hay una mejor, agradeceria que me la pasasen xD) que quiero que si el usuario no entro un numero regrese el foco.

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Untitled Document</title>
  5. <script type="text/javascript">
  6. function formatNumber(v) {
  7.     var num = new Number(v.value);
  8.     if(isNaN(num) || num=='Infinity') {
  9.         v.value = '';
  10.         v.focus(); //he probado esto y tmb this.focus(); y no funciona, el foco nunca ocurre
  11.     } else {
  12.         v.value = num.toFixed(2);
  13.     }
  14. }
  15.  
  16. </head>
  17.  
  18. <input type="text" onblur="formatNumber(this)" />
  19. </form>
  20. </body>
  21. </html>


Ahora que checo, no funciona en firefox nada mas, en IE si

Última edición por rudy69; 10/02/2010 a las 17:01

Etiquetas: dar, foco
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:31.