SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending Date & Time String via hidden field?

    Hello,

    I'm updating a form that was originally created with Frontpage (I must say I truly dislike Frontpage). In the past I have often programmed forms that go to a database using ASP and VBScript. I'm a bit at a lost on was is the best way to do this with JavaScript (which I'm much less familiar with) in a way that it will be compatible with the automated Frontpage form...

    The date and time are sent as two different fields and I must put them both in one field.

    Frontpage is sending the form automaticly to an e-mail address and to a text document. Then someone at the other end merges the text document to their database... Here is the line of code in Frontpage that sends the form: (you'll see the date and time code in this line)
    Code:
    <!--webbot bot="SaveResults" u-file="_private/results_test.txt" s-format="TEXT/TSV" s-label-fields="TRUE" b-reverse-chronology="FALSE" s-email-format="HTML/PRE" b-email-label-fields="TRUE" b-email-subject-from-field="FALSE" s-email-subject="On-line Form" s-date-format="%m/%d/%Y" s-time-format="%H:%M" s-builtin-fields="Date Time" u-confirmation-url="temp.htm" s-email-address="temp@hotmail.com" startspan -->
    If I use a hidden field such as:
    Code:
    <input type="hidden" name="DateTime" value="Not initialized" size=100>
    And let's say I build a string that contains my Date and Time such as:
    Code:
    strDateTime == Date + Time
    1- is my string written correctly in JavaScript to contain my date and time?

    2- how do I attach this string to my hidden field so that Frontpage's automatic form system picks it up?

    I would much rather be doing this with ASP, put all my fields results in strings and send it to a database myself which I know how to do but unfortunatly, I must conform to this darn Frontpage form.

    Thanks in advance for your help!

    Julia

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Devon, UK
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you really need to worry about this in JavaScript? It's far easier (and more accurate) to find the current date/time server side when the form is being processed.

    If it must be done in JS, use something like:
    Code:
    document.form_name.onsubmit = function() {
      document.form_name.element_name.value = new Date();
      return true;
    }
    Note that the user's local PC time is sent - and it could be way off the actual time, or in another timezone.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Ceeb, i'll try that this weekend!

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...Actually, the above will only give me the date. I need date and time in the same string.

    Is new Time(); valid? Can I do the following?
    Code:
    strDate = new Date() & ", " & new Time()
    
    document.form_name.onsubmit = function() {
      document.form_name.element_name.value = strDate
      return true;
    }
    Thanks,
    Julia

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...Actually, the above will only give me the date.
    That's incorrect. Try executing this:
    Code:
    var now = new Date();
    alert(now);

  6. #6
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    Code:
    strDate = new Date().toString();
    instead of

    Code:
    strDate = new Date() & ", " & new Time()
    Hope this helps.

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! Thanks a lot!

    Julia

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    strDate = new Date().toString();
    Explicitly calling toString() shouldn't be necessary when assigning a Date object to the value attribute of a hidden form field--toString() will be called implicitly to make the necessary conversion, just as with an alert().


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
  •