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

id is undefined problem!

I just build a javascript function that writes some img tags into a
layer on mouseover but i have a problem i don't know how to solve.

Everything works fine if the user waits until the page is done loading,
but if the user activates the mouse over i get the error that my id is
undefined because the javascript hasn't crated the layer yet.

is there some kind of way that i can check if the layer has been
created or if the page is done loading etc.??

i refer to the id this way:

document.getElementById( containerName ).
please help me.

May 1 '06 #1
3 3156
Mokka said the following on 5/1/2006 8:04 AM:
I just build a javascript function that writes some img tags into a
layer on mouseover but i have a problem i don't know how to solve.

Everything works fine if the user waits until the page is done loading,
but if the user activates the mouse over i get the error that my id is
undefined because the javascript hasn't crated the layer yet.
if (document.getElementById('containerName')){
//code here
}

It is called feature/object detection.
is there some kind of way that i can check if the layer has been
created or if the page is done loading etc.??


See above.

Or, window.onload = new Function(){isLoaded=true};

And in your function:

if (isLoaded)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 1 '06 #2
Thanks Randy,

could i get you to modify this code with the window.onload function?
cant get it to wok myself...... ;(

------------------------------------------------------------------------------------------

var http_request = false;
var containerName ='tipRich';

function ShowPictures( url , tipRich)
{

containerName = tipRich;

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// See note below about this line
}
} else if (window.ActiveXObject) { // IE

try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = httpRequestReady;

http_request.open('GET', url, true);
http_request.send(null);

}

function httpRequestReady() {
// elem = document.getElementById( containerName );

if (http_request.readyState == 4) {
if (http_request.status == 200) {
//elem.setAttribute('innerHTML',
http_request.responseText);
document.getElementById( containerName ).innerHTML =
http_request.responseText;
} else {
alert('There was a problem with the request.');
}
}

}

------------------------------------------------------------------------------------------

May 2 '06 #3
Mokka said the following on 5/2/2006 4:36 AM:
Thanks Randy,
For what?

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
could i get you to modify this code with the window.onload function?
cant get it to wok myself...... ;(
Where do you think you are calling it window.onload? There is nowhere in
the code you posted a reference to window.onload
------------------------------------------------------------------------------------------

var http_request = false;
var containerName ='tipRich';

function ShowPictures( url , tipRich)
{
containerName = tipRich;
tipRich is undefined.

contatinerName = 'tipRich';

But, not sure why you define it again locally when it is defined
globally with the same value. Drop one of them. Probably this one since
you also refer to containerName in another function.
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{ http_request.overrideMimeType('text/xml');
// See note below about this line


I know what that line was for but there is no note "below" about that line.

<snip>

window.onload = ShowPictures;

Next, post a URL to a complete page that doesn't work.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
4
by: Mike | last post by:
I am having a problem when a field is spaces being undefined. I wasn't sure if the problem was Excel or Javascript, so I thought I would post here first. The users are able to select from a drop...
2
by: Quansheng Liang | last post by:
Hello, I struggled with the problem of "undefined reference to `vtable ...`" while migrating a project from windows to linux. After searching the google I removed all the inline functions and now...
1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
1
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no...
1
by: David Resnick | last post by:
I had a problem going from gcc 2.96 to gcc 3.2.3 and narrowed it down to the following code. The question is whether the problem is undefined behavior on the code's part or a compiler bug. ...
7
by: Andy Lomax | last post by:
The C99 standard contains various statements like this one (in this case, 6.5.16, assignment operator): >If an attempt is made to modify >the result of an assignment operator or to access it...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
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
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.