|
-
April 22nd, 2008, 01:41 AM
#1
'this.menu'
Hi every one I need someone to help me with javascript I'm receiving this error message -'this.menu' is not null or an object. its on this line:this.submenus = this.menu.getElementsByTagName("div");
this is part of my code
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="_ctl0_Head1"><title>
Careers in pharmacy - login
</title><link rel="stylesheet" type="text/css"
href="Admin/Design/spurintranet.css" /><link rel="stylesheet" type="text/css" href="Admin/Design/Menu.css" /><script type="text/javascript">
function SDMenu(id)
{
if (!document.getElementById || !document.getElementsByTagName)
return false;
this.menu = document.getElementById(id);
this.submenus = this.menu.getElementsByTagName("div");
this.remember = true;
this.speed = 3;
this.markCurrent = true;
this.oneSmOnly = true;
}
Last edited by PeejAvery; April 22nd, 2008 at 09:29 AM.
Reason: Added code tags.
-
April 22nd, 2008, 09:32 AM
#2
Re: 'this.menu'
Can you post more relevant code so that we can actually work with it?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
April 26th, 2008, 05:30 PM
#3
Re: 'this.menu'
 Originally Posted by msandlana
Hi every one I need someone to help me with javascript I'm receiving this error message -'this.menu' is not null or an object. its on this line:this.submenus = this.menu.getElementsByTagName("div");
this is part of my code
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="_ctl0_Head1"><title>
Careers in pharmacy - login
</title><link rel="stylesheet" type="text/css"
href="Admin/Design/spurintranet.css" /><link rel="stylesheet" type="text/css" href="Admin/Design/Menu.css" /><script type="text/javascript">
function SDMenu(id)
{
if (!document.getElementById || !document.getElementsByTagName)
return false;
this.menu = document.getElementById(id);
this.submenus = this.menu.getElementsByTagName("div");
this.remember = true;
this.speed = 3;
this.markCurrent = true;
this.oneSmOnly = true;
}
The only thing that can be inferred from the code you posted is that the ID supplied to the SDMenu function does not correspond to an element with the same id in the HTML.
I assume you have of course already checked this. However, you also need to ensure that the HTML has been loaded fully by the browser before carrying out any operations that require finding or manipulating the HTML. I suggest that if you have not already done so, put the calling code into the onload event handler for the window object.
Also, I suggest you put an error checker in the SDMenu function to test the document.getElementById operation returns an element and not null.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|