473,378 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 2184
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 hidden. Clicking the button should reverse this. ...
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. The code that seems to handle the expansion and...
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 href="mcControlPanel.php"...
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 selection is. This works fine with IE but not working...
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 = document.getElementById(objeto).style.display;...
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 the replace no's of the parts with this line of...
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 document.getElementById().style.XX to everything i need,...
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"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.