Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:24

Problem with style references in existing javascript code


Poster: Gayle
Dated: Monday June 14 2004 - 6:17:54 BST

I have been trialling your DHTML Menu and so far it has everything I'm looking for and more and is working brilliantly. Unfortunately however I've just discovered that one of my other scripts is now no longer working. The script is..

function expand(el) {
el2=eval(el)
if(el2.style.display == "none"){
el2.style.display="";
el2.expanded=true;
}
else {
el2.style.display="none";
el2.expanded=false;
}
}

and it expands or hides a div layer which is defined for example as...

<div id="alertbodyPaid style="display:none">

..a table with info etc usually here...

</div>

and is called via an href ..

<a href="##" class="green" target="_self" onClick="expand('alertbodyPaid'); return false" >Click Here to view</a>

I am now getting the following error message when clicking on the Href..

"Object doesn't support this property or message"

This is something I use quite frequently throughout the site and I need them to be able to work together. Although I'm able to write some basic javascript functions this is beyond my level of knowledge. It is something that seems to happen when the DHTML Menu is actually drawn. If I remove the drawmenu command there is no problem. I'm thinking that perhaps the default style properties have been changes in some way. Can you please help ...

Thanks
Gayle


Poster: Gayle
Dated: Monday June 14 2004 - 22:19:04 BST

Solved the problem. Don't know why but if i change the variable el2 to elval it no longer brings back an error. Phew. If anyone could tell me why however I'd be quite interested.

Thanks
Gayle


Poster: kevin3442
Dated: Monday June 14 2004 - 23:51:03 BST

Hi Gayle,

el2 is used internally by the menu system to refer to a menu item (e.g., element 2). Your function sets el2=eval(el). Since el2 isn't declared within the function, it won't be treated as a local variable (i.e., local to that function) if a global variable of the same name already exists. Since an el2 already existed globally, your function was assigning to the global el2, instead of a variable within your function. I'm betting that the conflict also screwed up part of the menu.

Anyway, changing the variable name in the function removed the conflict. You could probably also have resolved the conflict by declaring el2 locally, inside of the function. I.e., instead of el2=eval(el) you could have put var el2=eval(el). This would make a local el2 for use inside the function, but cut off access to the global el2 from within the function (which wouldn't have been a problem anyway).

So... you asked ;)

Kevin


Poster: Gayle
Dated: Tuesday June 15 2004 - 0:50:41 BST

I did ask and thanks very much for your reply. :oops: A useful lesson to remember.

Cheers
Gayle [/img]