Results 1 to 3 of 3

Thread: Capturing the system date into a form field

  1. #1
    Join Date
    Oct 2005
    Location
    Liverpool, UK
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Capturing the system date into a form field

    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.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    What you could do is have this code:
    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?
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    NGJ (06-23-2008)

  4. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Of course nothing like this will work for users with javascript disabled. If your form is something like:

    HTML Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    NGJ (06-23-2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •