473,549 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Reference to Undefined Variable" say what?

Markus
6,050 Recognized Expert Expert
I was just playing around with javascript today and i wanted to change the style of a table element with javascript.

The code i am using:
Expand|Select|Wrap|Line Numbers
  1. ChangeIt(id){
  2. var target = document.getElementById(id)
  3. var newColor = "#00ff33"
  4. target.style.color = newColor
  5. }
  6.  
The php (this is from withing a while loop):
[php]
echo("<tr bgcolor=".$bgco lor.">
<td id=\"s".$counte r."\" onclick=\"Chang eIt('s".$counte r."');\">\n") ;
echo $counter;
$counter++; //increment counter
echo("</td><td>\n");
echo($row['url']);
echo("</td><td>\n");
echo($row['Util_Uploaded']);
echo("</td></tr>\n");
}
[/php]

I'm trying to get an onclick event where it catches the ID of the tag and then changes the style of said tag.

I get this error though:
Event thread: click
Error:
name: ReferenceError
message: Statement on line 1: Reference to undefined variable: ChangeIt
Backtrace:
Line 1 of script
ChangeIt("s2");
At unknown location
[statement source code not available]

What am i doing wrong?

Thanks.
Oct 28 '07 #1
3 2523
Ferris
101 New Member
hi

change your javascript code into:

Expand|Select|Wrap|Line Numbers
  1. function ChangeIt(id){
  2.           var target = document.getElementById(id);
  3.           var newColor = "#00ff33";
  4.           target.style.color = newColor;
  5. }
  6.  
hope it helps.
Oct 28 '07 #2
Markus
6,050 Recognized Expert Expert
How stupid am i!?!

I would've stewed over that for hours, over a simple 'function'. I can't believe i missed that, haha.

Thanks a bunch man :D
Oct 28 '07 #3
Markus
6,050 Recognized Expert Expert
New problem:

If i add some if and else statements in, i get the Reference to Undefined Variable ChangeIt

Expand|Select|Wrap|Line Numbers
  1. function ChangeIt(id){
  2. var target = document.getElementById(id)
  3. var newColor = "#00ff33"
  4. if(target.bgColor != newColor){
  5.     target.bgColor = newColor
  6. } else {
  7.     target.bgColor = "#ffffff"
  8. }
  9.  
Problem solved, hah.
Missed the last '}' out

:)
Oct 28 '07 #4

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

Similar topics

7
20337
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But , for example, when the file doesnt exists, i should not return any reference to a bad constructed object, so i need something as a NULL reference...
4
2511
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 going on with it. Thanks.
49
14439
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 http://www.webreference.com/programming/javascript/gr/column9/ they say: <snip> The undefined property A relatively recent addition to JavaScript is the undefined property.
8
11137
by: Dom | last post by:
This is a little tricky, but I think the error I'm getting isn't valid. The compiler just doesn't know my logic. MyObject o; switch (IntVariable) { case 1: o = new MyObject() break;
8
6278
Motoma
by: Motoma | last post by:
Good evening everyone. I am starting to re-explore C++, and I wanted to build a singleton class. Unfortunately, when I set things up as I do in PHP, it doesn't work out for me. I hope that the problem is something small and obvious, but here is what I have: #include <iostream> using namespace std; class ClientManager {
0
7541
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7734
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7979
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7826
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6065
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.