472,345 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

Why AJAX content won't display with document.getElementByID().style.display in IE8?

Hi All,

I'm seeing a strange issue with my code below. The content received thru the xmlHttpRequest, is not being displayed in IE8, after clicking the link. It is displayed only after moving the mouse/cursor, after clicking the link. Anyone sees what could be the problem here ? Please help.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5.    var xmlHttpfunction;
  6.    function ShowHint(id)
  7.    {
  8.       xmlHttp = GetXmlHttpObject();
  9.  
  10.       if (xmlHttp == null)
  11.       {
  12.          alert ("Browser does not support HTTP Request");
  13.          return;
  14.       }
  15.  
  16.       var url = "myurl.php";
  17.       url = url+"?id="+id;
  18.       xmlHttp.onreadystatechange = stateChanged;
  19.       xmlHttp.open("GET",url,true);
  20.       xmlHttp.send(null);
  21.    }
  22.  
  23.    function stateChanged()
  24.    {
  25.       if (xmlHttp.readyState === 4)
  26.       {
  27.          document.getElementById("elementRight").style.display = "block";
  28.          document.getElementById("elementRight").innerHTML = xmlHttp.responseText;
  29.       }
  30.    }
  31.  
  32. </script>
  33. </head>
  34. <body>
  35.       <div id="elementLeft">
  36.          <ul >
  37.             <li>
  38.                <a href="#" onclick="ShowHint("1");"> Item1 </a>
  39.             </li>
  40.             <li>
  41.                <a href="#" onclick="ShowHint("2");"> Item1 </a>
  42.             </li>
  43.             <li>
  44.                <a href="#" onclick="ShowHint("3");"> Item1 </a>
  45.             </li>
  46.          </ul>
  47.       </div>
  48.       <div class="element" id="elementRight">
  49.       </div>
  50. </body>
  51. </html>
  52.  
The css for 'element' is -
Expand|Select|Wrap|Line Numbers
  1. .element {
  2.         overflow:hidden;
  3.         border:1px;
  4.         border:#7CAFBE solid 1px;
  5.         height:50%;
  6.         width:79%;
  7.         float:right;
  8.         padding:0 0 0 10px;
  9.         padding-left:1px;
  10.         z-index:1000;
  11.    }
  12.  
Many Thanks,
csoft
Jan 24 '11 #1
3 2128
Oralloy
985 Expert 512MB
csoft,

I am surprised that you're seeing anything at all, considering the apparent syntax errors in lines 38, 41, and 44, where you have apparently violated HTMLs quoting rules. For example:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="ShowHint("1");"> Item1 </a>,
Should probably be:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="ShowHint('1');"> Item1 </a>,
Nevertheless, since it is working, that is not the fundamental problem that you're encountering...

The second problem I see is that you aren't stopping the anchor link in your code snippet. You probably should add a return false; to each of the events, like this:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="ShowHint('1'); return false;"> Item1 </a>,
Luck!
Oralloy
Jan 24 '11 #2
Oralloy,

Thanks for responding.

This was a typo, while copying the code -
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="ShowHint("1");"> Item1 </a>
  2.  
Sorry about that.

I now have the following, as you suggested -
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="ShowHint('1');return false;">
  2.    Item1
  3. </a>
  4.  
But, I still see the same result.

Actually, when I click on the link 'Item1', a dotted border around 'Item1' appears and only when I move the mouse arrow out of this dotted border, the content is loaded. Has this got anything to do with the anchor tag itself ? The following is the css for the anchor tag -

Expand|Select|Wrap|Line Numbers
  1. a {
  2.         color:#000000; 
  3.         text-decoration: none;
  4.         font-family: verdana;
  5.         font-size: 11px;
  6.         padding:0 0 0 10px; 
  7.         text-align: center;
  8.         cursor: pointer;
  9. }
  10.  
Thanks Again,
csoft
Jan 25 '11 #3
Oralloy
985 Expert 512MB
You may be running into variable scoping rules with xmlHttp.

Try hoisting the onreadystatechange to an anonymous function, like this:
Expand|Select|Wrap|Line Numbers
  1.    function ShowHint(id) 
  2.    { 
  3.       xmlHttp = GetXmlHttpObject(); 
  4.  
  5.       if (xmlHttp == null) 
  6.       { 
  7.          alert ("Browser does not support HTTP Request"); 
  8.          return; 
  9.       } 
  10.  
  11.       var url = "myurl.php"; 
  12.       url = url+"?id="+id; 
  13.       xmlHttp.onreadystatechange =
  14.         function(){
  15.           if (xmlHttp.readyState == 4) 
  16.           { 
  17.             document.getElementById("elementRight").style.display = "block"; 
  18.             document.getElementById("elementRight").innerHTML = xmlHttp.responseText; 
  19.           } 
  20.         }
  21.       xmlHttp.open("GET",url,true); 
  22.       xmlHttp.send(null); 
  23.    } 
Also, I changed the state comparison from absolute equality (===) to simple equality (==).

Luck!
Oralloy
Jan 25 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stewart | last post by:
Hi Experts. Please put the code sample below into an html document and take a look at in NN6+. One span should be shown while the other is...
7
by: PaulB | last post by:
Good Morning everybody, I'm trying to adapt a tutorial script that will handle the behaviour of an "Expanding/Contracting" site-navigation menu....
2
by: Jake Barnes | last post by:
Imagine I've this block of HTML: <p>Alex Schein Mailing List <input type="checkbox" name="newslettersToUse" value="133156"> (<a...
1
by: RonY | last post by:
I have a dropdown which calls SetTimePeriod method on change the selection. In the JS function, I reset the field style.display based on what the...
4
by: Winston | last post by:
Where is the mistake? I want to make a simple menu. These are two pieces of two files... function ShowMenu(objeto) { is_open =...
2
by: mandarchalke29 | last post by:
Can you please tell me that document.getElementById("").style.display="Inline" what does this statement will do.
4
omerbutt
by: omerbutt | last post by:
hi there i am amking an inventory application with php,ajax,javascript,html,dhtml,sql the problem is that i have hidden the input fields regarding...
2
by: jmatos | last post by:
I need to change the style of an element changing its padding-left property (got it in firefox but IE is a different battle..). I can use...
2
by: dgourd | last post by:
I cant get the style.display property to work properly. I have this test html page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.