Post Date with JavaScript
Douglas Karr at 8:42 amYou can use Javascript to post hidden variables, such as Date, to another system when building a Web Form. Here’s an example:
In the <head> of your HTML:
<script language=”javascript”>
function addDate {
var date=new Date();
var month=date.getMonth() + 1;
var day=date.getDate();
var year=date.getYear();
document.myForm.myDate.value = month+”/”+day+”/”+year; return true;
}
</script>
Within the <form> tag:
<form action=”pagetopostto.php” name=”myForm” method=”post” onsubmit=”return addDate();”>
And within the form elements:
<input type=”hidden” name=”myDate”>
How does this work? From the bottom up…
- There’s an empty variable called DateSubscribed in the form.
- On the submission of the page, the addDate Javascript function is called.
- That takes today’s date and sets the value of DateSubscribed to it. The function returns True to the form, letting it know that it can be submitted.


No comments yet.