Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    kee
    kee is offline
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post how can I make a dynamic date and time into form ?

    I would like to know how can I make a dynamic time (2:58:08 AM) and date (dd/mm/yyyy) into a form like textfield.the date will auto increasing like
    2:58:08 AM
    2:58:09 AM
    2:58:10 AM
    2:58:11 AM

    I have a script to show the time already (no date scipt yet) but I can't put it into the textfield. I'm not good in Java Script.

    Then, when we submit a form , it will send the current value of date and time to a program to do some works.

    Thank you
    Kee

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    just set the form value with the time script you have....

    document.FormName.ElementName.value = theTimeVariable

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    kee
    kee is offline
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now, I can do it. I have a two text field. The first is time text field, and date text field. the problem is that I can't invoke both of date and time.
    my code is following :
    <script language="javascript">

    var my12_hour = 1;
    var dn = "";

    function show_clock()
    {
    var Digital = new Date();
    var hours = Digital.getHours();
    var minutes = Digital.getMinutes();
    var seconds = Digital.getSeconds();

    if (my12_hour) {
    dn = "AM";
    if (hours > 12) { dn = "PM"; hours = hours - 12; }
    if (hours == 0) { hours = 12; }
    } else {
    dn = "";
    }
    if (minutes <= 9) { minutes = "0"+minutes; }
    if (seconds <= 9) { seconds = "0"+seconds; }

    myclock = hours+':'+minutes+':'+seconds+' '+dn;

    document.kee.time.value = myclock;

    setTimeout("show_clock()",1000);
    }
    function show_date()
    {
    today = new Date () ;
    Year=today.getYear();
    if (Year < 1000)
    Year+=1900 + 543
    Date=today.getDate();

    document.kee.date.value = Date + "/" + today.getMonth()+"/"+Year+""
    }
    </script>
    then , I used "<BODY onLoad="show_clock(), show_date()">". It makes the clock textfield don't increase the time. How can I fix them ?

    Thank you
    Kee

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You need to separate function calls with semicolon not comma.
    But you can make it as a single function by just including the date part in the show_clock() function.

    Change this line:

    document.kee.time.value = myclock;

    to:

    document.kee.time.value = Digital.getDate() + "/" + (Digital.getMonth()+1) + "/" + Digital.getFullYear() + " " + myclock;

    and then onload:

    <BODY onLoad="show_clock()">
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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