Results 1 to 2 of 2

Thread: Timestamp button

  1. #1

    Thread Starter
    Lively Member mattalexx's Avatar
    Join Date
    Mar 2002
    Location
    Gloucester, MA
    Posts
    77

    Timestamp button

    Hi everyone,

    I would like to have a button that enters the current date & time into a text box. This date/time does not need to update or anything (unless the timestamp button is pressed again.

    There is probably an easy solution to this problem, but I don't know much JS.

    Thanks a million in advance!
    Matt Alexander
    [email protected]

    Don't click here.

    Odigo: 5408962
    AIM: mattalexx
    ICQ: 138006220

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Code:
    <head>
       <script language="JavaScript">
          function getTimestamp() {
             today = new Date();
             hours = today.getHours();
             minutes = today.getMinutes();
             seconds = today.getSeconds();
    
             if (hours < 10)
                hours = "0" + hours;
             if (minutes < 10)
                minutes = "0" + minutes;
             if (seconds < 10)
                seconds = "0" + seconds;
    
             month = today.getMonth()+1;
             date = today.getDate();
             year = today.getFullYear();
    
             if (month < 10)
                month = "0" + month;
             if (date < 10)
                date = "0" + date;
    
             document.formName.textField.value = month + "/" + date + "/" + year + "   " + hours + ":" + minutes + ":" + seconds;
          }
       </script>
    </head>
    
    <body>
       <form method="post" action="#" name="formName">
          <input type="text" name="textField" value="" size="30"><br>
          <input type="button" onClick="getTimestamp();">
       </form>
    </body>
    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

Posting Permissions

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



Click Here to Expand Forum to Full Width