locked
Current Date/Time RRS feed

  • Question

  • User-110847984 posted

    Hi,

    I'm trying to assign the current date to the hidden field SndDate and the current time to the hidden field SndTime.
    Here is the code I’m using in the two files.

    File Tform.htm contains the following code:

    <html>
    <head>
    <meta http-equiv="Content-Language" content="pt">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    </head>
    <body>
     <form method="POST" action="tsend.asp" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">
      <p>
      &nbsp;<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="x" --><input type="text" name="ClienteID" size="20"></p>
      <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
      <input type="hidden" name="SndDate" value="">
      <input type="hidden" name="SndTime" value="">
     </form>
     </body>
    </html>

    File Tsend.asp contains the following code:

    <head>
    </head>
    <%
    dim Mail
    Set Mail = Server.CreateObject("Persits.MailSender")

    LcUser=Request.ServerVariables("LOGON_USER")
    LcAgen=Request.ServerVariables("HTTP_USER_AGENT")
    LcAddr=Request.ServerVariables("REMOTE_ADDR")

    Mail.Host = "localhost"
    Mail.From = "Sender_Address@somesite.com"
    Mail.FromName = "WebSite Form"
    Mail.AddAddress "Destination_Address@somesite.com"
    Mail.Subject = "Form Results"
    Mail.IsHTML = True
    Mail.Body = "<HTML><BODY><LEFT>"+"Cliente ID: "+Request("ClienteID")+"<P>User: "+LcUser+"<P>Address: "+LcAddr+"<P>User Agent: "+LcAgen+"<P>"+"Date: "+Request("SndDate")+"<P>"+"Time: "+Request("SndTime")+"<P></LEFT></BODY></HTML>"

    On Error Resume Next
    Mail.Send

    If Err <> 0 Then
    Response.Write "An error occurred: " & Err.Description
    end if

    %>

    <body>
    <div align="center">
    &nbsp;</div>
    </body>

    Can anyone help?

    Thursday, March 15, 2018 1:16 AM

All replies

  • User-460007017 posted

    Hi CNTLM,

    I think it is not difficult to get current date value and you only need to use document.getElementById().value to grant the current date to your SndTime hidden input control.

    https://stackoverflow.com/questions/12409299/how-to-get-current-formatted-date-dd-mm-yyyy-in-javascript-and-append-it-to-an-i

    Best Regards,

    Yuk Ding

    Thursday, March 15, 2018 9:29 AM
  • User906018781 posted

    Put something like this just before the closing </body> tag in TForm.htm.  It presumes .toLocaleString() is "dd/mm/yyyy, hh:mm:ss AM/PM".  Depending on your location and user population, you may need a more robust solution.

    <script>
       var d = (new Date()).toLocaleString().split(',');
       document.getElementsByName('SndDate')[0].value = d[0];
       document.getElementsByName('SndTime')[0].value = d[1].Trim();
    </script>

    It's unclear to my why you'd send this as it should be the same as getting Now() on the server unless you're looking for TZ information by doing so.  Particularly, as it will show the time the form was rendered, not when the submit occurred.

    Thursday, March 22, 2018 9:21 PM
  • User-110847984 posted

    Hi,

    I tried that sugestion, but it did not work.

    Meanwhile someone else in another forum give me a suggestion that worked and I’m using it.
    Thanks, any way for trying to help.

    Tuesday, April 10, 2018 11:47 AM