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 5 of 5

Thread: entering time

  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    entering time

    I want a button on my web page which when clicked inserts the current time in corresponsind text box.

    (please note that i dont want to continue showing the current time. When someone clicks the button, the current time at that point is inserted in a text box on the form).

    I understand this isnt that tough but i am a newbie with programming :-)

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    What you have tried so far? homework?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    Read the Forum Rules re homework. I must be in a relaxed mood today.

    But the following has some deliberate mistakes in it which you must put right.

    Code:
    <form name = "myForm">
    <input type = "button" value = "Click To Insert Current Time" onclick = "setClock()">
    <input type = "text" name = "timeDisplay">
    
    
    <script type="text/javascript"
    
    function setClock() {
    var today = new Date();
    var hh = today.getHours();
    if (hh <10) {hh = 0 + hh;
    var mm = today.getMinutes();
    if (mm <10) {mm = "0" + mm}
    var ss = today.getseconds();
    if (ss <10) {ss = "0" + ss}
    var tim = hh + ":" + mm + ":" + ss;
    document.myform.timeDisplay.value = time;
    }
    
    </script>
    It is your responsibility to die() if necessary….. - PHP Manual

  • #4
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Got a mistake there:
    Code:
    var tim = hh + ":" + mm + ":" + ss;
    document.myform.timeDisplay.value = time;
    it's either time at the variable definition or tim at the next line.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    As I said, the code includes some deliberate mistakes. I am willing to help the OP but not serve it up on a plate for him. He is supposed to find out these mistakes for himself.


  •  

    Posting Permissions

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