SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Timestamp in a Web Form

    I need to capture submit Date and Time in a web form. I have the following:

    <script>
    <!--
    function formCheck(formobj){
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    curr_month++;
    var curr_year = d.getFullYear();
    var curr_hour = d.getHours();
    var curr_min = d.getMinutes();
    if (curr_min.length == 1)
    {
    curr_min = "0" + curr_min;
    }
    thisform.SubmitDate.value=curr_month + "/" + curr_date + "/" + curr_year;
    thisform.SubmitTime.value=curr_hour + ":" + curr_min;
    }
    -->
    </script>

    <form name="thisForm" action="/support-files/mailer.asp" method="post" onsubmit="return formCheck(this);">
    <INPUT TYPE="HIDDEN" NAME="SubmitDate" />
    <INPUT TYPE="HIDDEN" NAME="SubmitTime" />
    .
    .
    .

    This looks to me like I should get SubmitDate and SubmitTime in my form results but I don't. What am I doing wrong? Thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,260
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    javascript time

    Hi masscraft, welcome to the forums,
    I didn't look at your code too closely yet. But I wanted to know if you're sure you want to do this with javascript. Javascript is client-side so users could save the page, modify the code/form, and submit bogus time info. Besides that, javascript gets the user's computer time. So a user's time, even if correct, would be for thier timezone, and if they wanted to, they could change it and submit bogus time info.
    If this time info is to be for anything that needs it to be accurate, I suggest you add the time server-side, and even then you may need to adjust for timezone location of the server.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2007
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not a server-side person, but it seems what you need is more server-side.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with the others, this is best done server side. However, if this is non-critical and is only an enhancement, then try changing these lines:

    thisform.SubmitDate.value=...
    thisform.SubmitTime.value=...

    to this:

    document.forms['thisform'].SubmitDate.value=...
    document.forms['thisform'].SubmitTime.value=...

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even better add an id to your elements eg
    Code:
    <input type="hidden" name="SubmitDate" id="SubmitDate" />
    and then use the new way to get elements
    Code:
    document.getElementByid('SubmitDate').value =...
    You'll thank me in the long run for using this way
    Mashups, DOM Scripting and all the things we call Web2.0 blogger
    http://www.heavyweightgeek.org/
    http://twitter.com/heavyweightgeek

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh and yes I agree this should be done on the server for lots of things but I've assumed that you wanting to capture there local time for whatever reason
    Mashups, DOM Scripting and all the things we call Web2.0 blogger
    http://www.heavyweightgeek.org/
    http://twitter.com/heavyweightgeek


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
  •