"var is undefined" when passing from onClick

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tarantulus
    New Member
    • May 2007
    • 114

    "var is undefined" when passing from onClick

    Hi guys,

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

    my link code is:

    Code:
    <a href="404.html" onclick="getContent('test'); return false;">something</a>
    and my javascript is
    Code:
    function getContent()
            {
            if (window.XMLHttpRequest)
              {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
              }
            else
              {// code for IE6, IE5         
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }      
            xmlhttp.onreadystatechange=function()
              {
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                  document.getElementById("main-content").innerHTML=xmlhttp.responseText;
                }
              }      
            xmlhttp.open("POST","./lib/page.php",true);
            xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xmlhttp.send("page_id=" + id)
            xmlhttp.send();
            }
    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
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    does that occur in line 20? where is that variable id declared and/or where do you assign a value to it?

    Comment

    Working...