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 8701035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:18:02+00:00 2026-06-13T02:18:02+00:00

I have a simple script that i am testing with, but its acting very

  • 0

I have a simple script that i am testing with, but its acting very odd. I call a script which loads and i have it to a particular td id, I then call a second script and add that to different td id but for some reason it wipes out the first div’s content even though they are seperate.

This is what i have:

function call_back(result,div_id,func){
        document.getElementById(div_id).innerHTML = result;
        if(typeof(func) != 'undefined'){func();}
}


function caller(url,cfunc)
{
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
                xmlhttp.onreadystatechange=cfunc;
                xmlhttp.open("GET",url,true);
                xmlhttp.send();
}


function call_file(url,div_id,func){
    caller(url,function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            call_back(xmlhttp.responseText,div_id,func);
        }
    });
}

I then have this on my onload:

 window.onload = function(){
    stage = 6;      
call_file('test.html','menu_left');

    switch(parseInt(stage)){
    case 6: call_file('test2.html','main'); break;
   }
};

The problem arises with the case statement. If i remove the case statement the contents added with test.html loads fine, but if i add the case statement, content from test.html disappears and then only test2.html displays.

The html for the id’s are:

            <table class="body_wrapper">
                <tr>
                    <td class="menu_left" id="menu_left"></td>
                    <td class="main" id="main"></td>
                </tr>   
            </table>

Why might this be happening?

  • 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-06-13T02:18:02+00:00Added an answer on June 13, 2026 at 2:18 am

    The problem has nothing to do with the switch statement. As you are calling the ajax request for some local files and it is already cached, the call_back function is called twice before document.getElementById(div_id).innerHTML = result; executes and hence replaced by the variable values from the last call. If you just put an alert into the call_back function like below

    function call_back(result, div_id, func) {
      alert(result);
      document.getElementById(div_id).innerHTML = result;
      if (typeof (func) != 'undefined') { func(); }
    }
    

    you will find it is working. But as it is not a solution, alternatively if you modify this

    xmlhttp.open("GET", url, true);
    

    to

    xmlhttp.open("GET", url, false);
    

    it will work but you will loose the asynchronous feature of AJAX.

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

Sidebar

Related Questions

I have a simple script im testing which calls a HTML file. In that
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have a simple jQuery script that I'm trying to build upon but I
I have a very simple file upload PHP script. I am testing with a
I have this simple script that I'm working on. I must admit, I'm totally
I have a simple script that does some search and replace. This is basically
I have a simple script that pulls about 100 million results, 1 million at
I have a simple Ruby script that uses the rb-appscript gem to control iTunes,
I have a simple Python script that uses a signal handler for Ctl-C. If
I have a simple Python script that uses the socket module to send a

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.