JavaScript - Fecha en campo

 
Vista:

Fecha en campo

Publicado por Gemma (6 intervenciones) el 09/07/2001 18:01:53
¿Como le añado la fecha actual en un campo?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Fecha en campo

Publicado por Nano (53 intervenciones) el 10/07/2001 01:39:33
Trata con esto,
<html>
<script>
var meses = new Array();
meses[1]=" Enero ";
meses[2]=" Febrero ";
meses[3]=" Marzo ";
meses[4]=" Abril ";
meses[5]=" Mayo ";
meses[6]=" Junio ";
meses[7]=" Julio ";
meses[8]=" Agosto ";
meses[9]=" Septiembre ";
meses[10]=" Octubre ";
meses[11]=" Noviembre ";
meses[12]=" Diciembre ";

function getFecha(){
var fecha=new Date();
var dia=fecha.getDate();
var mes=fecha.getMonth()+1;
var mestxt = meses[mes];
var anio=fecha.getFullYear();
var numero=fecha.getDay();
var nombre;
switch (numero){
case 1 : nombre = "Lunes"; break;
case 2 : nombre = "Martes"; break;
case 3 : nombre = "Miércoles"; break;
case 4 : nombre = "Jueves"; break;
case 5 : nombre = "Viernes"; break;
case 6 : nombre = "Sábado"; break;
case 0: nombre = "Domingo"; break;
}
var hoy = nombre + ", " + dia + mestxt + anio;
return hoy;
}

</SCRIPT>

<body onLoad="Javascript:document.miForma.miTexto.value=getFecha();">
<form name="miForma">
<input type="text" name="miTexto">
</form>
</body>
</html>

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar