473,839 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why AJAX content won't display with document.getEle mentByID().styl e.display in IE8?

2 New Member
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 2213
Oralloy
988 Recognized Expert Contributor
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
csoft ltd
2 New Member
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
988 Recognized Expert Contributor
You may be running into variable scoping rules with xmlHttp.

Try hoisting the onreadystatecha nge 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
1949
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 hidden. Clicking the button should reverse this. However it doesn't. Removing the table structure from around the text fixes it, but I need the table structure (this is very simplified example). Hope someone can provide an alternative?
7
6002
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. The code that seems to handle the expansion and contraction follows at the bottom of my message here. This following line is a big part of my hang-up: document.getElementById('m1').style.display='none';
2
9081
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 href="mcControlPanel.php" onClick="hideOrShowDivById('emailList133156'); return false;">See emails?</a>)</p> <form method="post" action="mcControlPanel.php" id="emailList133156" style="display:none;"><textarea name="formInputs">nazjeehaj@son.org,
1
9045
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 selection is. This works fine with IE but not working with Firefox browser. The firefox browser has problem to display a field after its style.display is reset. At the end of the JS function, I printed out the fields style.display value. They are set correctly. How to resovle this? My JS is : ...
4
2186
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 = document.getElementById(objeto).style.display; document.getElementById("menu_p").style.display='none'; if (is_open == 'none') { document.getElementById(objeto).style.display='block'; }
2
22046
by: mandarchalke29 | last post by:
Can you please tell me that document.getElementById("").style.display="Inline" what does this statement will do.
4
2031
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 the replace no's of the parts with this line of code document.getElementById('bgrp1').style.visibility='hidden'; document.getElementById('lable_rp_no1').style.display='none'; document.getElementById('rp_no1').style.display='hidden'; the code for the html part is here
2
13913
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 document.getElementById().style.XX to everything i need, except with padding-left, as it is separated by a ' - ' and it is not correct to use it as it was supposed to: document.getElementById('el').style.padding-left = '5px' will throw 'invalid assignment left-hand side', as expected.. Any help...
2
1936
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" "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>Test Javascript</title> <script language="javascript" type="text/javascript"> ...
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10910
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10654
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7833
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4493
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.