Ver Mensaje Individual
  #16 (permalink)  
Antiguo 10/08/2010, 15:28
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 3 meses
Puntos: 126
Respuesta: Campos para calcular edad

Hola

Al final tendrás que dejar de pagar a ese profesor y pagarme a mi
Código Javascript:
Ver original
  1. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  2. <html xmlns='http://www.w3.org/1999/xhtml'>
  3. <head>
  4. <meta name="http-equiv" content="Content-type: text/html; charset=UTF-8"/>
  5. <script type="text/javascript">
  6. function calcular_edad() {
  7. var fecha = null;
  8. var fecha = prompt("Fecha de nacimiento","");
  9. if (fecha == null || fecha == "") {
  10. alert ("Escribe tu fecha de nacimiento");
  11. } else {
  12. var hoy = new Date()
  13. divFecha = fecha.split("/");
  14. var editFecha = new Date(divFecha[2],divFecha[1],divFecha[0])
  15. diferencia =  hoy.getTime() - editFecha.getTime();
  16. segundostotales = parseInt(diferencia /1000);
  17. anyos = parseInt(segundostotales/60/60/24/365);
  18. alert(anyos)
  19. }
  20. }
  21. </script>
  22. </head>
  23. <body>
  24. <input type="button" onclick="calcular_edad(); return false;"; value="Fecha" />
  25. </body>
  26. </html>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />