-
Timestamp button
Hi everyone,
I would like to have a button that enters the current date & time into a text box. This date/time does not need to update or anything (unless the timestamp button is pressed again.
There is probably an easy solution to this problem, but I don't know much JS.
Thanks a million in advance!
-
Code:
<head>
<script language="JavaScript">
function getTimestamp() {
today = new Date();
hours = today.getHours();
minutes = today.getMinutes();
seconds = today.getSeconds();
if (hours < 10)
hours = "0" + hours;
if (minutes < 10)
minutes = "0" + minutes;
if (seconds < 10)
seconds = "0" + seconds;
month = today.getMonth()+1;
date = today.getDate();
year = today.getFullYear();
if (month < 10)
month = "0" + month;
if (date < 10)
date = "0" + date;
document.formName.textField.value = month + "/" + date + "/" + year + " " + hours + ":" + minutes + ":" + seconds;
}
</script>
</head>
<body>
<form method="post" action="#" name="formName">
<input type="text" name="textField" value="" size="30"><br>
<input type="button" onClick="getTimestamp();">
</form>
</body>
-Matt