Post Date with JavaScript
Happy New Year! Marketing Technology finds and reports on the latest technology that will enable your business to effectively market to your audience, for acquisition or retention strategies. Subscribe now the Marketing Technology Blog RSS feed or to the Marketing Technology Email to have new content sent directly to your inbox. You'll also find my other business blog helpful, Social Media Domination.
You 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.