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

  • Home
  • SEARCH
  • 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 7653053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:55:41+00:00 2026-05-31T11:55:41+00:00

So what I have is pretty simple. I click a button on my main

  • 0

So what I have is pretty simple. I click a button on my main php page and it runs two functions. One creates a colorbox using a php page (with only html) and then the second function alters elements of the page using javascript. However, for some reason the second function doesn’t work 50% of the time! When testing this on XAMPP (local servers), it works perfectly, but when testing remotely, the second function sometimes doesn’t run.

Now here is my code to go more in depth (if needed). This is the my main page HTML/PHP code. onclick runs two functions (again, the second sometimes doesn’t work):

<img src="<?php echo visualizeStatus($t11Status, 11) ?>" alt="" width="130" height="105" id="table11img" onclick="showColorBox(); infoBoxPopulate(11)"/>

showColorBox() really only just opens a colorbox:

function showColorBox()
{
    $.colorbox({href:"infoBox.php", left: 400, top: 100, opacity: 0.40});
}

infoBox.php is what is loaded into the colorbox and it’s just an html page, no particular reason why I used .php. This is what it looks like (bad styling only on this copy/paste, couldn’t get it to format without losing the “code sample” thing. All you need to know is I give elements id’s so I can edit them in the next function:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Table Info</title>

</head>

<body>
<font color="#450505" size =+5"><div id="tableinfo_number">Table # Error</div></font>
<br>
   <font size ="+2"><div id="tableinfo_status">Table Status Error</div>
    <div id="tableinfo_party">Party: N/A</div>
   <div id="tableinfo_orders">Orders: N/A</div></font>
<br>
<br>

<hr>
    <center><p><img id= "tableinfo_seatP" src="images/info_seat.png" width="92" height="42" onclick="showSeatBox(window.tableNumWin)"/><img id= "tableinfo_oneUp" src="images/info_increaseOne.png" width="45" height="50" onclick="increasetStatus(window.tableNumWin)" /><img id= "tableinfo_notif" src="images/info_notification.png" width="56" height="53" onclick="makeRequest(window.tableNumWin)"/></p></center>
</body>
</html>

Alright, so that page is loaded into the colorbox. Now, what the second function, infoBoxPopulate(11), does is it just does a javascript/ajax function. It edits two parts of the colorbox php page. One doesn’t even require the php code to do this, yet they both fail at the same time when they do fail.

function infoBoxPopulate(tIDin)
{
    // This needs to wait until colorbox is loaded, then do this code.
    var tID = tIDin;
    var tStatus;

    window.tableNumWin = tID;
    //var oneUpJS = document.getElementById("tableinfo_oneUp");
    //oneUpJS.onclick = function() {increasetStatus(tID);} 

    if (window.XMLHttpRequest)
    {     // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp4=new XMLHttpRequest();
    }
    else
    {     // code for IE6, IE5
            xmlhttp4=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp4.onreadystatechange=function()
    {
        document.getElementById("tableinfo_number").innerHTML= "Table: " + tID;
        document.getElementById("tableinfo_status").innerHTML= xmlhttp4.responseText;
        populateParty(tID);
    }   
    xmlhttp4.open("GET","populateStatus.php?tID="+tID,true);
    xmlhttp4.send();
}

Again, populateStatus just does a query that then returns the responseText. So, I think I just am misunderstanding how this code is run. Why would it not work more often when done remotely… possibly because it takes more time to reach the SQL server? I would assume that once the php page is loaded that I can edit any elements of it using javascript, but that doesn’t appear to be the case. Please 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-31T11:55:42+00:00Added an answer on May 31, 2026 at 11:55 am

    Here’s what probably happens:

    1. When you’re testing on local server, the time of the server response is lower than the time of your colorbox execution, so once javascript is ready to launch infoBoxPopulate the server response is already downloaded and ready to use. JS is single threaded, so only one function at a time is executed.
    2. When your testing from remote server, the time of exchange between your server and your testing machine is bigger than the JS execution time (the colorbox AJAX call is asynchronous, so it doesn’t block the code execution), so sometimes your JS code gets executed without having access to the response. This is so-called racing condition.

    The solution is to use an hook provided by your colorbox and launch the function after the colorbox told you it’s ready:

    <img src="<?php echo visualizeStatus($t11Status, 11) ?>" alt="" width="130" height="105" id="table11img" onclick="showBoxAndPopulate();"/>
    <script type="text/javascript">
      function showBoxAndPopulate()
      {
          $.colorbox({
            href:"infoBox.php",
            left: 400,
            top: 100,
            opacity: 0.40,
            onComplete: function() { infoBoxPopulate(11); }
          });
      }
    </script>
    

    Check callbacks on colorbox site to find the one that suits you the best.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple case which I started solving using foreach(), but then
I have a pretty simple form with a listbox, a text box, and two
I have a pretty simple scenario. I have the following HTML: <h1>Hello</h1> <input type="button"
i have pretty simple simple question (i hope so). How do i change the
I have a pretty simple ASP.NET Web Form that looks a bit like the
I have a pretty simple Linq to XML query: var q = from c
I have a pretty simple SQL I need to perform. I have a ProcessUser
I have a pretty simple question which perhaps someone familiar with Server/Client design &
I have a pretty simple problem. Basically I have an array called $list that
I have a pretty simple UIScrollView defined inside Interface Builder. I've pasted in some

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.