PDA

View Full Version : Capturing the system date into a form field



NGJ
05-14-2008, 09:35 AM
Hi,

I'd like to append the system date to the 'Subject' field of an email form.
Having no control over the .asp mailing script I have to use, I have to get the value into the field before the post.

<script type="text/javascript" language="JavaScript">
<!--
var calendarDate = getCalendarDate();
document.write (calendarDate);
//-->
</script>

Given I have something like this above to get the date, can someone please suggest how I achieve:

<input type="hidden" name="mailsubject" value="my subject"> + calendarDate


Thanks in advance,
N.

PS: I appreciate that the received date would be displayed in the message header row in Outlook, etc.:D

Nile
05-14-2008, 12:05 PM
What you could do is have this code:


<script type="text/javascript">
<!--
function timein(){
var date = new Date()
var dateout = date.getHours()+":"+date.getMinutes()+ "<sub>"+date.getSeconds()+"</sub>&nbsp;&nbsp;&nbsp;"+date.getMonth()+1+ "/"+date.getDate()+ "/"+date.getFullYear();
document.getElementById('dt').innerHTML=dateout;
}
setInterval("timein()",5);
//-->
</script>

And have dt be a hidden input(id="dt"). But then you would need to get that data from the page. So I don't know. Just giving a little thought that maybe you can ask to change the mail form on the page?

jscheuer1
05-14-2008, 01:58 PM
Of course nothing like this will work for users with javascript disabled. If your form is something like:


<form action="whatever_makes_this_send_mail" method="post" onsubmit="this.elements['mailsubject'].value=getCalendarDate();return true;">
<input type="hidden" name="mailsubject" value="my subject">
whatever else is in the form
</form>

It should at least work for javascript enabled users. It's the onsubmit event and the presence of the input that are important here, the rest of the form can be as it normally would be.