Ver Mensaje Individual
  #6 (permalink)  
Antiguo 27/11/2011, 22:17
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?

disculpas amigo, lo tenia hecho pero me comi el body al copiar y pegar

aca va completo
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(campo,val_num){
  14.  
  15. var elvalor = document.getElementById(campo).value;  
  16. if(es_numero(elvalor)){
  17.  
  18. if(elvalor > val_num){
  19. document.getElementById(campo).value= val_num;
  20. alert("Número mayor que "  +val_num + "\n\rsu número: " + elvalor);
  21. document.getElementById(campo).style.backgroundColor = "red";
  22. }else{
  23. document.getElementById(campo).style.backgroundColor = "#FFF";
  24. }
  25.  
  26. } else{
  27. alert("Debe ingresar un número");
  28. document.getElementById(campo).style.backgroundColor = "red";
  29. }
  30.  
  31. }
  32. //]]>
  33. </head>
  34. <form action="#">
  35. <p>
  36. El campo debe de tener un valor y este ser menor ó igual a 5    <br />
  37. <input type="text" name="edad" id="edad" onblur="comprobar(this.id,5)" /><br />
  38. El campo debe de tener un valor y este ser menor ó igual a 130  <br />
  39. <input type="text" name="edad" id="peso" onblur="comprobar(this.id,130)"/>
  40. </p>
  41. </form>
  42. </body>
  43. </html>

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

Última edición por emprear; 28/11/2011 a las 11:48 Razón: gramática