Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4273408
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:42:32+00:00 2026-05-21T07:42:32+00:00

I am trying to implement a Javascript/PHP/AJAX clock into my website so that I

  • 0

I am trying to implement a Javascript/PHP/AJAX clock into my website so that I can have a simple clock which can operate in different timezones (tutorial is here http://networking.mydesigntool.com/viewtopic.php?tid=373&id=31)

This itself works fine, but I already have a javascript stopwatch running on the page, and the 2 seem to clash and the clock won’t display while the stopwatch is working.

This is the script for the clock:

<script type="text/javascript">
function loadTime ()
{
http_request = false;
if(window.XMLHttpRequest)
{
    // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if(http_request.overrideMimeType)
    {
        // set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
    }
}
else if(window.ActiveXObject)
{ // IE
    try
    {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try
        {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e)
        {
        }
    }
    }

    var parameters = "time=";
    http_request.onreadystatechange = alertContents;
    http_request.open('POST', 'time.php', true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);
}


function alertContents()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
            result = http_request.responseText;
            document.getElementById('clock').innerHTML = result;
        }
    }
}

</script>
<body onload="setInterval('loadTime()', 200);">

and this is the code for the stopwatch:

<script type="text/javascript">
    window.onload = function()
    {
        stopwatch('Start');
    }

    var sec = 0;
    var min = 0;
    var hour = 0;
    function stopwatch(text) {
        sec++;
        if (sec == 60) {
            sec = 0;
            min = min + 1;
        } else {
            min = min;
        }
        if (min == 60) {
            min = 0; 
            hour += 1;
        }

        if (sec<=9) { sec = "0" + sec; }
        document.clock.stwa.value = ((hour<=9) ? "0"+hour : hour) + " : " + ((min<=9) ? "0" + min : min) + " : " + sec;

        if (text == "Start") { document.clock.theButton.value = "Stop "; }
        if (text == "Stop ") { document.clock.theButton.value = "Start"; }

        if (document.clock.theButton.value == "Start") {
            window.clearTimeout(SD);
            return true;
        }
        SD=window.setTimeout("stopwatch();", 1000);
    }

    function resetIt() {
        sec = -1;
        min = 0;
        hour = 0;
        if (document.clock.theButton.value == "Stop ") {
            document.clock.theButton.value = "Start";
        }
        window.clearTimeout(SD);
    }
</script>

Could someone help me get them to work side-by-side please?

Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:42:33+00:00Added an answer on May 21, 2026 at 7:42 am

    For one, your’re declaring an onload event handler in your HTML:

    <body onload="setInterval('loadTime()', 200);">
    

    which is consequently overwritten in script:

    window.onload = function()
    {
        stopwatch('Start');
    }
    

    This means the original onload call is never executed.

    You should try using addEventListener so you can add multiple event handlers to the same event.

    A couple more points:

    • Don’t pass a string to setInterval and setTimeout, just pass the function itself. More efficient and less error-prone: setInterval(loadTime, 200);
    • Instead of writing all that JS code to work with different browsers, use jQuery, mootools, or one of the gazillion other frameworks. They make it a lot easier to get it right on all browsers.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no experience with jquery or javascript for that matter. I am trying
I'm a noob at Javascript, but I'm trying to implement something on my website
I am currently trying to implement this into my current code: http://cubiq.org/iscroll I have
Im trying to implement some code i found on a website which duplicates a
I've been trying to determine whether I can implement AJAX & SSL, so this
I'm trying to implement a dynamic OPTION list in JavaScript. Depending on other selections
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
We are trying to implement a REST API for an application we have now.
Using PHP, and MySql, I am trying to implement this rather snazzy in-place editor
I am trying to implement the Ajax feature in the comments section of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.