469,898 Members | 1,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

"var is undefined" when passing from onClick

Tarantulus
114 100+
Hi guys,

I'm trying to initiate an ajax event from an onclick.

my link code is:

Expand|Select|Wrap|Line Numbers
  1. <a href="404.html" onclick="getContent('test'); return false;">something</a>
and my javascript is
Expand|Select|Wrap|Line Numbers
  1. function getContent()
  2.         {
  3.         if (window.XMLHttpRequest)
  4.           {// code for IE7+, Firefox, Chrome, Opera, Safari
  5.           xmlhttp=new XMLHttpRequest();
  6.           }
  7.         else
  8.           {// code for IE6, IE5         
  9.           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  10.           }      
  11.         xmlhttp.onreadystatechange=function()
  12.           {
  13.           if (xmlhttp.readyState==4 && xmlhttp.status==200)
  14.             {
  15.               document.getElementById("main-content").innerHTML=xmlhttp.responseText;
  16.             }
  17.           }      
  18.         xmlhttp.open("POST","./lib/page.php",true);
  19.         xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  20.         xmlhttp.send("page_id=" + id)
  21.         xmlhttp.send();
  22.         }
in an external file

I cannot for the life of me work out why I'm getting "id is undefined" errors in firefox, can you guys give me some pointers?

Thanks in advance
Oct 16 '10 #1
1 1585
gits
5,390 Expert Mod 4TB
does that occur in line 20? where is that variable id declared and/or where do you assign a value to it?
Oct 16 '10 #2

Post your reply

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

Similar topics

13 posts views Thread by Don Vaillancourt | last post: by
3 posts views Thread by Adam Toline | last post: by
188 posts views Thread by infobahn | last post: by
1 post views Thread by Pavils Jurjans | last post: by
4 posts views Thread by Flip | last post: by
49 posts views Thread by matty | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.