Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/11/2011, 22:57
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Limitar valor maximo en un input?

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>número mayor que</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. // con esta función comprobás que sea un número
  9. function es_numero(input){
  10. return !isNaN(input)&&parseInt(input)==input;
  11. }
  12. //ahora verificas que sea no sea mayor que 5
  13. function comprobar(){
  14.  
  15. var laedad = document.getElementById('edad').value;  
  16. if(es_numero(laedad)){
  17. if(laedad > 5){
  18. alert("Número mayor que 5\n\rsu número: " + laedad);
  19. document.getElementById('edad').value= 5;
  20. }
  21. } else{
  22. alert("Debe ingresar un número");
  23. }
  24.  
  25. }
  26. //]]>
  27. </head>
  28. <form action="#">
  29. <p>
  30. El campo debe de tener un valor y este ser menor ó igual a 5    <br />
  31. <input type="text" name="edad" id="edad" onblur="comprobar()"/>
  32. </p>
  33. </form>
  34. </body>
  35. </html>

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