Hi there,
I'm trying to write a function that will prepopulate a form date field with the current (todays) date. However I'm not doing to well. Does anybody have or know of a function that will do this for me?
Thanks in advance,
C
<script>
function fillWithToday(formElm)
{
var today = new Date();
var year = today.getFullYear();
var month = today.getMonth()+1;// + 1 because its an array
var day = today.getDay();
formElm.value = day + "/" + month + "/" + year
}
</script>
Gary's example give you 2/4/2002 where 2/ = the second day of the week, because today.getDay(); returns the day of the week [values between 0(Sunday) and 6 (Saturday))
To get the day of the months you have to use: var day = today.getDate();
Sorry to improve you Gary ;-)
Erik
<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.