473,326 Members | 2,012 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,326 software developers and data experts.

"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 1686
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

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

Similar topics

13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
5
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on this...
3
by: Adam Toline | last post by:
In reference to the following: http://www.bellecose.com/form.htm At the top of each column there is a box for "All". When one is checked I need to check all of (and only) those boxes...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
4
by: Flip | last post by:
I'm seeing one of my websites giving me an error message on the page after it loads up as "WXBUnit Undefined" What does that mean? The formatting of the site is horrible! I'm not sure what is...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
5
by: Jason | last post by:
Hello, I am trying to dynamically create a table, then set its <td>'s onclick: var table = document.createElement("table"); var row = table.insertRow(-1); var td = row.insertCell(-1);...
5
by: Nathan Sokalski | last post by:
I have an ASP.NET application which is giving the following JavaScript error: 'theForm' is undefined However, when I do a View Source one of the <scriptelements is as follows: <script...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.