View Full Version : getDate...got it working...one last STEP!

01-31-2007, 10:12 PM
I need to get the date to write into an Input box in the body of my page.

I have the date working using the following code:

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)

This displays the date on the top of the page. I need it to display the date INTO an INPUT BOX placed in the BODY of my page.

Any help would be appreciated.


01-31-2007, 10:41 PM
You use document.getElementById('mydatefield').value= month + "/" + day + "/" + year

so use <input type=text id="mydatefield" ReadOnly value="" size=10> in your html body.

tested and working

btw is there away to use value=getmydate() in the html?
Or value can not get a return string from a function?

02-01-2007, 10:09 AM
I would have been more consistent in HTML coding

<input type="text" id="mydatefield" readonly="readonly" value="" size="10">