Jump to content

Count up appear in Textbox


demeritrious

Recommended Posts

I would appreciate if someone could figure this out or tell me the easiest way to do this. I need a count up counter that appears in a textbox so I can record the time a user is on a page. On a side note, I do have their Start and finish time timestamp recorded in myphpadmin database but I am looking for the easiest (or best) way to do this. Any advice or scripts would be very much appreciated.

 

Thanks in advanced.

 

I did find this counter that works but the numbers appear 0.0.1 if counting up. I don't want to confuse the user. I really want to display to the user how long they was on a certain page.

<script>
  $(document).ready(function() {
    var time = '00:00:00',
        parts = time.split(':'),
        hours = +parts[0],
        minutes = +parts[1],
        seconds = +parts[02],
        input = $('#timeInput');
 
    var timer = setInterval(function(){
        seconds++;
        if(seconds == 60) {
            seconds = 00;
            minutes++;
 
            if(minutes == 60) {
                minutes = 00;
                hours++;
            }
        }
        var newTime = hours + ":" + minutes + ":" + seconds;
        $('#timeInput').val(newTime);
    }, 1000);
 
});
</script>
 
<input type="text" name="time" id="timeInput"/>
Link to comment
https://forums.phpfreaks.com/topic/291058-count-up-appear-in-textbox/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.