473,387 Members | 1,771 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,387 software developers and data experts.

Error: 'document.getElementById(...)' is null or not an object.

3
Hi
when i m trying to execute my ajax code using a link to display datas from another page named second.php.,
i got an error when the page loads in "ie"., which runs perfectly in firefox.,

here is my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. var i;
  4. function httprequest(i)
  5. {
  6.  
  7. var xmlhttp;
  8. try
  9. {
  10.  xmlhttp=new XMLHttpRequest();
  11. }
  12. catch(e)
  13. {
  14.   try
  15.   {
  16.   xmlhttp=new Activexobject("Msxml2.XMLHTTP");
  17.   }
  18.   catch(e)
  19.   { 
  20.     try
  21.     {
  22.     xmlhttp=new Activexobject("MICROSOFT.XMLHTTP")
  23.     }
  24.     catch(e)
  25.     {
  26.      alert("ur browser doesnot support Ajax");
  27.      return false;
  28.     }
  29.   }
  30.  
  31. }
  32. xmlhttp.onreadystatechange=function()
  33.  if(xmlhttp.readyState==4)
  34.  { 
  35.  
  36.    obj = document.getElementById( "idname" );
  37.  
  38.    obj.innerHTML = xmlhttp.responseText;
  39.    getBufferText();
  40.  
  41.  }
  42. }
  43.  
  44. xmlhttp.open("GET", "second.php?i="+i,true);
  45. xmlhttp.send(null);
  46. }
  47.  
  48. function call_sec(i)
  49. {
  50.  httprequest(i)
  51. }
  52. </script>
  53.  
Expand|Select|Wrap|Line Numbers
  1. <table id="idname">
  2.  
  3. .............
  4. first page contents
  5. .................
  6.  
  7. <a onclick="call_sec(<? echo $i;?>)">second</a></table>
  8.  


when the page loads i get an error "Error: 'document.getElementById(...)' is null or not an object"
but works well with firefox.,

could anyone help me.,
its very urgent.,

thanks
Mar 20 '08 #1
8 5575
gits
5,390 Expert Mod 4TB
you have a typo - use:

Expand|Select|Wrap|Line Numbers
  1. new ActiveXObject
  2.  
in your IE section for creating the request-object.

kind regards
Mar 20 '08 #2
vjayis
134 100+
you have a typo - use:

Expand|Select|Wrap|Line Numbers
  1. new ActiveXObject
  2.  
in your IE section for creating the request-object.

kind regards

Hi

tried doing with the changes above., but still didnt get rid of the problem.,

thanks
Mar 21 '08 #3
gits
5,390 Expert Mod 4TB
please try to use a div instead of a table first ...

kind regards
Mar 21 '08 #4
vjayis
134 100+
please try to use a div instead of a table first ...

kind regards
Hi

tried changing to <div > tag., but not yet got the solution., when the page loads., i get the same error.,

thanks
Mar 22 '08 #5
gits
5,390 Expert Mod 4TB
when the page loads? the XMLHttpRequest should be triggered by the buttonclick ... isn't it? what code is executed onload of the page?

kind regards
Mar 22 '08 #6
ananjy
3
when the page loads? the XMLHttpRequest should be triggered by the buttonclick ... isn't it? what code is executed onload of the page?

kind regards

Hi

No code is executed on onload of the page.,
The only script on my page is the javascript used for ajax.

I hav enabled script debugging in browser setting., and get tht error which displays in the aert 'document.getElementById('...'') is null or not an object.,

if i disable the script debugging
the page gets loaded well., and displays the result in the status bar as
"done, but with some errors on the page".,

here is my code again

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var id;
  3. var action;
  4.  
  5.  
  6. function ajaxFunction(id,action)
  7. {
  8.  
  9. var xmlHttp;
  10. try
  11.   {
  12.   // Firefox, Opera 8.0+, Safari
  13.   xmlHttp=new XMLHttpRequest();
  14.   }
  15. catch (e)
  16.   {
  17.   // Internet Explorer
  18.   try
  19.     {
  20.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  21.     }
  22.   catch (e)
  23.     {
  24.     try
  25.       {
  26.       xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  27.       }
  28.     catch (e)
  29.       {
  30.       alert("Your browser does not support AJAX!");
  31.       return false;
  32.       }
  33.     }
  34.   }
  35.  
  36. xmlHttp.onreadystatechange=function()
  37.  if(xmlHttp.readyState==4)
  38.  { 
  39.  
  40.    document.getElementById("ajax").innerHTML=xmlHttp.responseText;
  41.  }
  42. }
  43.  
  44. xmlHttp.open("GET","ajax.php?id="+id+"&action="+action,true);
  45. xmlHttp.send(null);
  46.  
  47. }
  48.  
  49. function hidden(id,action)
  50. {
  51.  ajaxFunction(id,action)
  52. }
  53.  
  54. </script>
  55.  

kind regards
vijay
Mar 26 '08 #7
gits
5,390 Expert Mod 4TB
the only part i could see where the error could come from is here:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("ajax")
do you have a node with id = 'ajax' in your document? ...

kind regards
Mar 26 '08 #8
ananjy
3
the only part i could see where the error could come from is here:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("ajax")
do you have a node with id = 'ajax' in your document? ...

kind regards



Hi got solution for the error,
i just simply added an if condition before tht line and got the solution.,
and thanks for tht.,

but after the page gets loaded.,
it displays the message in status bar as.,
"Done, but with some errors on page."

what might be the error???

how can i get an solution for this.,

regards
Mar 27 '08 #9

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

Similar topics

3
by: Matt | last post by:
I tried to display all html control types in the form. But it has run time error "object doesn't support this property or method" on document.write(obj.type); Even I do document.write('hello...
4
by: dubing | last post by:
Hi, Our webpage uses the following JavaScript code. function toggleSubmenu(divId, link) { var div = document.getElementById(divId); div.style.display = (div.style.display == 'block') ?...
1
by: Andrew Phillipo | last post by:
I have some code that works everywhere but IE5.0, including IE5.5. Here is a snippet of where the code seems to go wrong: Location.prototype.change = function(current) { this.current = current;...
11
by: westplastic | last post by:
This one is driving me insane. The script works perfect on Firefox, but Internet Explorer keeps complaining about "Error Object Expected" and stuff like that. I've run it through Firefox's Java...
1
by: ABC | last post by:
If there have a page which have unknown '<div>' label or may be no any controls. I want add 'onclick' events to call server event to do something. But there are no any events of 'Document' object...
3
by: sfeher | last post by:
Hi All, The following code returns a valid xmlDoc (since I can evaluate and selectNodes) but its value is "xmlDoc= null" ?! Or at least this is what the FireBug shows and (xmlDoc===null) is...
8
by: ipy2006 | last post by:
In my HTML I have, <input type="button" class="cartonsumkey" value="Sum Cartons" onclick="sumup(this);" /> In an external file that is called in Head area, I have, function sumup( o ) { ...
7
by: juliejam | last post by:
Hello all, I am new here and hope some kind, smarter than me person can help. I am getting the error object expected with the following code: function click(e); here the error says it...
1
by: pratimapaudel | last post by:
function Showdiv() { var SelectStates = document.getElementById('Select1').value; if(SelectStates ="3") { document.getElementById("div2").style.display = "block"; } else ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.