Click to See Complete Forum and Search --> : Problem when use CSS to Create Popup menu


chucuoi
12-12-2003, 09:44 PM
My example to make a rectangle, and it's background is Blue.
I want to build a MouseOut Event for the Rectangle, This Event performing the task: when I move Mouse out of the Rectangle, the Rectangle will Invisible. (This action will use to build a Drop Down Menu...). But My code contains an Error that i can't repair it. Can you help me Step by Step... Thank you very much!

The Error : "Object dosen't suport this property or method"
After Debug by Microsoft Enviroment, it show me these line:

function anonymous() {
menu1.outHandle();return false;
}

Here is my Code:
(I run my code on IE6, my Computer uses WindowsXP and Internet Information Services (IIS) are installed on my Computer. )

<HTML>
<Title>Simple Example </Title>
<Head></Head>
<Body>
<Script language = "JavaScript">
function MEvenInit()
{
document.all[this.vname].onmouseout= new Function(this.vname + ".outHandle();return false;");
}

function Mout()
{
document.all[this.vname].style.visibility="hidden";
}

function MWriteDIV()
{
document.write("<DIV ID =" + this.vname + "></DIV>")
}

function MWriteCSS()
{
document.write("<Style type = 'text/css'>");
document.write("#" + this.vname + "{position : absolute;background-color:blue;width :" + this.W + ";height:" + this.H + ";cursor : hand;visibility: visible}");
document.write("</Style>");
}


function Menu(id,vname,link,W,H)
{
this.ID=id;
this.vname=vname;
this.link=link;
this.W=W+ "px" ;
this.H=H+ "px";
this.outHandle=Mout;
this.WriteCSS=MWriteCSS;
this.EvenInit=MEvenInit;
this.WriteDIV=MWriteDIV;
}


M1 = new Menu(1,"menu1","http://vnexpress.net",50,50);
M1.WriteCSS();
M1.WriteDIV();
M1.EvenInit();
</Script>
<Body>
</HTML>

batfink
12-14-2003, 06:40 PM
WTF!

See if this helps....

<HTML>
<Head><Title>Simple Example </Title>
<Script language = "JavaScript">
function Mout()
{
document.getElementById(vname).style.visibility="hidden";
}
function MWriteDIV()
{
document.write("<DIV style='color:black' ID =" + vname + " onMouseOut='Mout()'>" + _link + "</DIV>")
}

function MWriteCSS()
{
document.write("<Style type = 'text/css'>");
document.write("#" + vname + "{position : absolute;background-color:blue;width :" + W + ";height:" + H + ";cursor : hand;visibility: visible}");
document.write("</Style>");
}

var vname= "menu1";
var _id=1;
var _link = "http://vnexpress.net";
var W = 80 + "px";
var H = 50 + "px";
MWriteCSS();
MWriteDIV();
</Script>
</Head>
<Body>

</body>
</HTML>

tips:
Do not use reserved words like id or link
Generally (not always) put script in the head. Check tags as you body had no ending /
The title tags must go in the head tags.

Hope I was not too harsh.

chucuoi
12-14-2003, 07:22 PM
Wow... , thanhk you very much, Batfink. Now I see the way to create Pop Up menu.

Now, can u teach me any more : What's wrong in my code if I want to use the InitEvent Function for specified the MouseOut Event fixed on my Object?

function MEvenInit()
{
document.all[this.vname].onmouseout= new Function(this.vname + ".outHandle();return false;");
}

How to repair it???

Thanks alot, Batfink.

batfink
12-15-2003, 05:12 AM
As you can see in the adjusted code the blue square does become invisible onMouseOut already.

I took your code: function MEvenInit()
{
document.all[this.vname].onmouseout= new Function(this.vname + ".outHandle();return false;");
}

and fit it in another simpler way. Not sure what you want now.

chucuoi
12-16-2003, 12:51 AM
Thank u. Here, i've found the error, u see
The Function Menu don't have the folow nessasary code: eval(this.vname + "=this");
If u put this line to the Function Menu as last line code, my Example will run.
Hope you'll teach me more.
Thank you very much, Batfink!