Ver Mensaje Individual
  #4 (permalink)  
Antiguo 19/11/2002, 11:08
Avatar de mikel_gomez
mikel_gomez
 
Fecha de Ingreso: febrero-2001
Mensajes: 482
Antigüedad: 23 años, 3 meses
Puntos: 3
Re: Cargar valores de formulario.

twinsen2:

La función fecha() solo debería devolver la fecha para ser generalista como tú dices. Luego puedes tener otra(s) funciones en ficheros externos o en la misma página que te carguen las cajas de texto adecuadamente, y lo mejor es que se llamaran a través del evento onload y no detrás mismo del <input> para evitar problemas en aquellos casos en que el navegador intenta ejecutar el script antes de cargar el formulario completo.
Código:
<html>
  <head>
    <script type="text/javascript">
    <!--
      function fecha() {
        var hoy  = new Date();
        var dia  = hoy.getDate();
        var mes  = hoy.getMonth() +1;
        var anyo = hoy.getYear();
        var fh   = dia + '/' + mes + '/' + anyo;
        return fh
      }
      function cargaFechas() {
        document.prueba.fechaDesde.value = fecha();
        document.prueba.fechaHasta.value = fecha();
      }
    //-->
    </script>
  </head>
  <body onload="cargaFechas()">
    <form name="prueba">
      <table>
        <tr>
          <td>Desde:</td>
          <td>
            <input type="text" name="fechaDesde" value="" />
          </td>
          <td>Hasta:</td>
          <td>
            <input type="text" name="fechaHasta" value="" />
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>
Saludos.
__________________
Mikel Gómez
Hay que aprender mucho para saber poco