Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2011, 12:29 PM   PM User | #1
naveendk.55
New Coder

 
Join Date: Aug 2011
Posts: 88
Thanks: 5
Thanked 0 Times in 0 Posts
naveendk.55 is an unknown quantity at this point
Question Time picker in input text box

Hi,

I'm trying to display a time clock in input text box. The time should display in Time utilization box after clicking on START BUTTON.

I tried the below code and it is not starting the time. However, I tried the javascript individually and it worked. Any help?


PHP Code:

<script type="text/javascript">
            var seconds = 0;
            var minutes = 0;
            var hours   = 0;
    
            function zeroPad(time) {
                var numZeropad = time + '';
                while(numZeropad.length < 2) {
                    numZeropad = "0" + numZeropad;
                }
                return numZeropad;
            }

            function countSecs() {
                seconds++;

                if (seconds > 59) {
                    minutes++;
                    seconds = 0;
                }
                if (minutes > 59)
                {
                    hours++
                    minutes = 0;
                                
                }
                document.getElementById("time_utilization").innerHTML = zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds);
            }

            function startTimer() {
                action = window.setInterval(countSecs,1000);
            }

        </script>

    </head>
    <body>
<?php include("header.php"); ?>

<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content">
<div class="art-post">
<div class="art-post-body">
<div class="art-post-inner art-article">

<form name="tracker" method="post" action="processor.php" onsubmit="return formCheck(this);">

<ul>

<li class="mainForm" id="fieldBox_8">
<label class="formFieldQuestion">Start Time&nbsp;*</label><input readonly class=mainForm type=text name=start_time id=start_time size='30' value=''> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" id="start1_time" style="width: 100px" Value="Start Time" onClick="startTimer()"></li>


<li class="mainForm" id="fieldBox_12">
<label class="formFieldQuestion">Time Utilization</label><input class=mainForm type=text  name="time_utilization" id="time_utilization" size='8' value='00:00:00' ></li>
<br /> <br />
<li class="mainForm">
<input id="saveForm" class="mainForm" type="submit" value="Submit"  style="width : 100px"/>
   </li>
</form>

I am getting "Unknown Runtime Error at line 43". However, code has below line at link 43:

Code:
                document.getElementById("time_utilization").innerHTML = zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds);
naveendk.55 is offline   Reply With Quote
Old 12-27-2011, 02:48 PM   PM User | #2
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 302
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
Change line 43 to this, note that all I have changed is the innerHTML to value
Code:
document.getElementById('time_utilization').value = zeroPad(hours) + ':' + zeroPad(minutes) + ':' + zeroPad(seconds);
needsomehelp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:56 AM.


Advertisement
Log in to turn off these ads.