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.